本帖最后由 钟雯 于 2022-12-16 21:02 编辑
菜鸟一枚,不知道这个求助帖放在这里是不是超纲了。。我有一组数据,想用python帮忙分析里面的规律或者概率,目前只是将Excel替换了鸢尾花的数据,用的是svc,但好像还是不够准确,下面是我的代码,有没有大牛可以帮我完善一下。。还是本身就没啥规律。。。
如同时满足([[9,20,10,25]]),([[11,0,10,25]]),([[7,22,10,25]]), 答案为30 如同时满足([[22,30,0,12]]),([[29,4,0,12]]),([[25,4,0,12]]), 答案为0
import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
iris_data = load_iris()
X_train,X_test,y_train,y_test = train_test_split(\
iris_data['data'],iris_data['target'],random_state=0)
# 做出预测
X_new = np.array([[10,0,5,22]])
import numpy
from sklearn.svm import SVC
svmClf = SVC(random_state=42)
svmClf.fit(X_train, y_train)
all_pre_and_get_score = svmClf.decision_function(X_new)
all_pre_and_get_score
# Softmax函数
def Softmax(s : list or numpy.ndarray):
S = numpy.array([numpy.exp(i) for i in s])
u = numpy.sum(S)
for j in S:
yield j/u
# 转换看下个数字出现的概率
for i in Softmax(all_pre_and_get_score):
print(i)
aa = numpy.array(i)
bb = aa.tolist()
m2=bb.copy()
m2.remove(max(bb))
m3=max(m2)
m4=m2.copy()
m4.remove(max(m2))
m5=max(m4)
print()
print(max(i), '{}'.format(bb.index(max(bb))))
print(m3,'{}'.format(bb.index(max(m2))))
print(m5,'{}'.format(bb.index(max(m4))))
|