繁体   English   中英

如何提高python中大数据程序的速度

[英]How to improve speed of the program for large data in python

我正在尝试计算预测概率。 我编写了一个正在计算的程序,但速度非常慢,并且为大型数据集花费了太多时间。

目的是通过使用LinearSVCOneVsRestClassifier计算 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))

有没有其他方法可以完成相同的任务? 请建议

如果您需要使用predict_proba方法,您可以使用 sklearns CalibratedClassifierCV

或者你可以使用Logistic Regression

如果您的问题与速度有关,请尝试考虑在LinearSVC中使用sklearn.svm而不是SVC(kernel='linear') 它更快。

正如另一个答案中所建议的, LinearSVCSVC(kernel='linear')快。

关于概率,SVC 没有predict_proba() 相反,您必须将其probability超参数设置为True 关联

提示: SVM 更适合小数据集,所以更喜欢使用其他算法来处理大数据集。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM