我根据我的训练数据集预测一些值并计算概率,将它们相加总是给我 1 或 100% 这是我的训练数据
Address Location_ID
Arham Brindavan,plot no.9,3rd road Near ls Stn,cannop 4485
Revanta,Behind nirmal puoto Mall, G-M link Road, Mulund(W) 10027
Sandhu Arambh,Opp St.Mary's Convent, rose rd, Mulund(W) 10027
Naman Premirer, Military Road, Marol Andheri E 5041
Dattatreya Ayuedust Adobe Hanspal, bhubaneshwar 6479
这是我的测试数据
Address Location_ID
Tata Vivati , Mhada Colony, Mulund (E), Mumbai 10027
Evershine Madhuvan,Sen Nagar, Near blue Energy,Santacruz(E) 4943
这是我尝试过的
import pandas as pd
import numpy as np
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.linear_model import SGDClassifier
data=pd.read_csv('D:/All files/abc.csv')
msk = np.random.rand(len(data)) < 0.8
data_train = data[msk]
data_train_add = data_train.ix[:,0] # divide dataset into training set
data_train_loc = data_train.ix[:,1]
data_test1 = data[~msk]
data_test = data_test1.ix[:,0] # divide dataset into testing set
data_train_add = np.array(data_train_add)
data_train_loc = np.array(data_train_loc)
count_vect = CountVectorizer(ngram_range=(1,3))
X_train_counts = count_vect.fit_transform(data_train_add.ravel())
tfidf_transformer = TfidfTransformer()
data_train_tfidf = tfidf_transformer.fit_transform(X_train_counts)
clf_svm = SGDClassifier(loss='log', penalty='l2', alpha=1e-3, n_iter=5, random_state=42).fit(data_train_tfidf, data_train_loc.ravel())
X_new_counts = count_vect.transform(data_test.ravel())
X_new_tfidf = tfidf_transformer.transform(X_new_counts)
predicted_svm = clf_svm.predict(X_new_tfidf)
clf_svm_prob=clf_svm.predict_proba(X_new_tfidf)
prob_sum=clf_svm_prob.sum(axis=1)
print(prob_sum)
O/P
array([ 1., 1., 1., 1.])
为什么它给出 1% 或 100% 的概率,我应该更改哪个参数以使概率总和正确..请提前建议谢谢。