【发布时间】:2018-07-03 07:18:17
【问题描述】:
使用“Machine Learning.csv”文件输入的逻辑回归。
#Import Libraries
import pandas as pd
#Import Dataset
dataset = pd.read_csv('Machine Learning Data Set.csv')
X = dataset.iloc[:, :-1].values
y = dataset.iloc[:, 10]
#Splitting the dataset into the Training set and Test set
from sklearn.cross_validation import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y, test_size = 0.2, random_state = 0)
#Feature Scaling
from sklearn.preprocessing import StandardScaler
sc_X = StandardScaler()
X_train = sc_X.fit_transform(X_train)
X_test = sc_X.transform(X_test)
#Fitting Logistic Regression to the Training Set
from sklearn.linear_model import LogisticRegression
classifier = LogisticRegression(random_state=0)
classifier.fit(X_train,y_train)
#Predicting the Test set results
y_pred = classifier.predict(X_test)
#Making the Confusion Matrix
from sklearn.metrics import confusion_matrix
cm = confusion_matrix(y_test,y_pred)
我有一个机器学习/逻辑回归代码 (python) 如上所述。它已经正确训练了我的模型,并且与测试数据非常匹配。但不幸的是,当我使用其他一些随机值进行测试时,它只会给我 0/1(二进制)结果。 (训练集只有 0/1 - 如失败/成功)
如何在此算法中获得概率结果而不是二进制结果?我尝试了非常不同的一组数字,并想找出失败的概率 - 而不是 0 和 1。
非常感谢任何帮助 :) 非常感谢!
【问题讨论】:
标签: python machine-learning regression