2016-11-16 18 views
0

您好,我有经过培训和测试的数据。我正在尝试使用sklearn的功能相关性Seelct K Best来选择相关功能并在之后绘制条形图。但是我得到这个错误:值:错误无法使用Sklearn特性相关性将字符串转换为浮点型

ValueError: could not convert string to float: B 

但我开始觉得我有在我的数据集列这样看这可能是问题:

CancellationCode: 
A 
B 
C 
D 

如果此列是导致问题我该如何解决这个错误 这里是我下面的代码:

import numpy as np 
from sklearn.feature_selection import SelectKBest, f_classif 
import matplotlib.pyplot as plt 

selector = SelectKBest(f_classif, k=13) 
selector.fit(X_train, y_train) 

scores_select = selector.pvalues_ 
print scores_select 


# Plotting the bar Graph to visually see the weight of each feature 
plt.bar(range(len(scores_select)), scores_select, align='center') 
plt.xticks(range(len(features_columns)), features_columns, rotation='vertical') 
plt.show() 

回答

2

你需要分类变量转化为假人。

df = pd.get_dummies(df) 
相关问题