【发布时间】:2018-10-30 12:10:24
【问题描述】:
我正在尝试计算预测概率。我写了一个程序,它正在计算,但速度非常慢,并且需要大量时间来处理大型数据集。
目的是使用LinearSVC和OneVsRestClassifier计算SVM模型中的每个预测概率但得到错误
AttributeError: 'LinearSVC' object has no attribute 'predict_proba'
由于上述错误,我在下面尝试了
代码
from sklearn import svm
model_1 = svm.SVC(kernel='linear', probability=True)
from sklearn.preprocessing import LabelEncoder
X_1 = df["Property Address"]
lb = LabelEncoder()
X_2 = lb.fit_transform(X_1)
y_1 = df["Location_Name"]
y_2 = lb.fit_transform(y_1)
test_1 = test["Property Address"]
lb = LabelEncoder()
test_1 = lb.fit_transform(test_1)
X_2= X_2.reshape(-1, 1)
y_2= y_2.reshape(-1, 1)
test_1 = test_1.reshape(-1, 1)
model_1.fit(X_2, y_2)
results = model_1.predict_proba(test_1)[0]
# gets a dictionary of {'class_name': probability}
prob_per_class_dictionary = dict(zip(model.classes_, results))
还有其他方法可以完成相同的任务吗?请建议
【问题讨论】:
-
我不确定我是否理解。您的代码是慢还是会引发错误?两个截然不同的问题。
-
我已经发布了一个帖子,但没有得到解决方案 [stackoverflow.com/questions/53040262/….我写了一个非常慢的代码。我在上面的代码中没有收到任何错误。
标签: python python-3.x machine-learning stanford-nlp