1

私は次のコードを持っています:

#load required library
library(data.tree)
library(entropy)
library(RWeka)
library(partykit)
library(FSelector)
library(e1071)
library(caret)
library(RWekajars)


#Load dataset
rest_contries <- fromJSON("https://restcountries.eu/rest/v1/all")
View(rest_contries)
class(rest_contries)
dim(rest_contries)
cleaned_rest_countries <- rest_contries[,c(1,2,5,6)]
View(cleaned_rest_countries)
#================ J48 Algorithm =================================================
m <- J48(region~., data = cleaned_rest_countries)
plot(m)

J48アルゴリズムからベイジアンネットワーク図をプロットすることになっています。次のエラーが表示される方法:

> m <- J48(region~., data = cleaned_rest_countries)
Error in .jcall(o, "Ljava/lang/Class;", "getClass") : 
  weka.core.UnsupportedAttributeTypeException: weka.classifiers.trees.j48.C45PruneableClassifierTree: Cannot handle string attributes!

問題の解決にご協力ください。CSV からデータを読み取るとうまくいきますが、json からは文字列属性エラーが発生します。

4

1 に答える 1

1

文字変数を因子に変換する必要があると思います。

> cleaned_rest_countries <- lapply(cleaned_rest_countries, as.factor)
> m <- J48(region~., data = cleaned_rest_countries)
> m
J48 pruned tree
------------------

subregion = :  (3.0)
subregion = Australia and New Zealand: Oceania (5.0)
subregion = Caribbean: Americas (27.0)
subregion = Central America: Americas (8.0)
subregion = Central Asia: Asia (5.0)
subregion = Eastern Africa: Africa (20.0)
subregion = Eastern Asia: Asia (8.0)
subregion = Eastern Europe: Europe (11.0)
subregion = Melanesia: Oceania (5.0)
subregion = Micronesia: Oceania (7.0)
subregion = Middle Africa: Africa (10.0)
subregion = Northern Africa: Africa (7.0)
subregion = Northern America: Americas (6.0)
subregion = Northern Europe: Europe (16.0)
subregion = Polynesia: Oceania (10.0)
subregion = South-Eastern Asia: Asia (11.0)
subregion = South America: Americas (15.0)
subregion = Southern Africa: Africa (5.0)
subregion = Southern Asia: Asia (9.0)
subregion = Southern Europe: Europe (16.0)
subregion = Western Africa: Africa (17.0)
subregion = Western Asia: Asia (17.0)
subregion = Western Europe: Europe (9.0)

Number of Leaves  :     23

Size of the tree :  24
于 2016-06-27T11:53:17.970 に答える