我有一个具有20个功能的.csv文件,根据这些功能,我想预测.csv文件中每一行的输出将为0或1。
我希望从具有浮点值的其他功能获得输出0或1
答案 0 :(得分:0)
import sklearn
import pandas as pd
from sklearn import tree
from sklearn import model_selection
from sklearn.metrics import accuracy_score
from sklearn.linear_model import LogisticRegression
df=pd.read_csv('filename.csv')
data = df.values.tolist()
labels = [0,1,0,0,1....... no.of rows times]
x_train,x_test,y_train,y_test=model_selection.train_test_split(data,labels,test_size=0.3,
random_state=42)
使用任何算法(此处为逻辑回归)
clf=LogisticRegression()
clf.fit(x_train,y_train)
print clf.score(x_test,y_test)*100
print clf.predict([.... 20 features values]);