首先,我使用以下Python代码删除了NA值:
import pandas as pd
a = pd.read_csv("true.csv",low_memory=False)
#print a
b = pd.read_csv("false.csv",low_memory=False)
merged = a.append(b, ignore_index=False)
merged=merged.dropna(axis=1)
merged.to_csv("out.csv", index=False)
之后我使用了Rattle,发现2列是分类的,我只想要数字数据。所以我使用以下代码删除了这些列:
cat("\nSTART\n")
startTime = proc.time()[3]
startTime
#--------------------------------------------------------------
# Step 1: Include Library
#--------------------------------------------------------------
cat("\nStep 1: Library Inclusion")
library(randomForest)
library(FSelector)
#--------------------------------------------------------------
# Step 2: Variable Declaration
#--------------------------------------------------------------
cat("\nStep 2: Variable Declaration")
modelName <- "randomForest"
modelName
InputDataFileName="out.csv"
InputDataFileName
training = 70 # Defining Training Percentage; Testing = 100 - Training
#--------------------------------------------------------------
# Step 3: Data Loading
#--------------------------------------------------------------
cat("\nStep 3: Data Loading")
dataset <- read.csv(InputDataFileName) # Read the datafile
dataset <- dataset[sample(nrow(dataset)),] # Shuffle the data row wise.
#result <- cfs(Features ~ ., dataset)
head(dataset) # Show Top 6 records
nrow(dataset) # Show number of records
names(dataset) # Show fields names or columns names
#--------------------------------------------------------------
# Step 4: Count total number of observations/rows.
#--------------------------------------------------------------
cat("\nStep 4: Counting dataset")
totalDataset <- nrow(dataset)
totalDataset
nums <- sapply(dataset, is.numeric)
dataset<-dataset[ ,nums]
#--------------------------------------------------------------
# Step 5: Choose Target variable
#--------------------------------------------------------------
cat("\nStep 5: Choose Target Variable")
target <- names(dataset)[1] # i.e. RMSD
target
#data(dataset)
result <- cfs(Activity ~ ., dataset)
在上面的代码中,我使用了最后一行来使用FSelector
进行特征选择。
执行最后一行后,我收到以下错误:
if(sd(vec1)== 0 || sd(vec2)== 0)返回(0)时出错:
缺少需要TRUE / FALSE的值
out.csv https://drive.google.com/open?id=0B3UWvP6zFBQnN3JiamloOWl3T28
答案 0 :(得分:1)
在最后一行之前
(result <- cfs(Activity ~ ., dataset))
使用
dataset$Activity = factor(dataset$Activity)
执行需要一些时间,因为我们有一个非常大的数据集。