Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/343.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 收入预测神经网络_Python_Neural Network - Fatal编程技术网

Python 收入预测神经网络

Python 收入预测神经网络,python,neural-network,Python,Neural Network,我正在尝试创建一个神经网络。因为我有1000多张名单,所以我剪了一张。 我看过很多教程,但我需要一些帮助: 我可以使用列表列表作为我的数据库而不是dic吗 # a[0] is the price # a[1] is the paid value # a[2] is my result from sklearn.neighbors import KNeighborsClassifier from pandas import DataFrame a = [[0.063807299, 0.71,

我正在尝试创建一个神经网络。因为我有1000多张名单,所以我剪了一张。 我看过很多教程,但我需要一些帮助:

我可以使用列表列表作为我的数据库而不是dic吗

# a[0] is the price
# a[1] is the paid value
# a[2] is my result


from sklearn.neighbors import KNeighborsClassifier
from pandas import DataFrame
a = [[0.063807299, 0.71, 0.00071],
     [0.363262854, 0.7, 0.0007],
     [0.836344317, 0.76, 0.00076]]

df = DataFrame(a)
df.columns = ['value1', 'value2', 'result']

X_train, y_train = df['value1'], df['value2']
knn = KNeighborsClassifier(n_neighbors=7)
knn.fit(X_train, y_train)
knn.score(X_train, y_train)


knn.predict([[1.2, 3.4]])
>>> 0.025  # This would be my results for example

是的,是的,你可以。这对于熊猫图书馆来说变得微不足道。首先需要导入熊猫,然后使用以下代码可以将列表列表转换为熊猫数据帧:

df = DataFrame(a, columns=headers)
然后,您可以使用以下设置培训集:

X_train, y_train = df['value1'], df['value2']
value2列应包含分类器要使用的标签。对于KNN分类器,标签不能是float类型,因此只需将其调整为整数即可解决问题

a = [[0.063807299, 71, 0.00071],
     [0.363262854, 7, 0.0007],
     [0.836344317, 76, 0.00076]]

lab_enc = preprocessing.LabelEncoder()
df = DataFrame(a)
df.columns = ['value1', 'value2', 'result']
X_train, y_train = df['value1'].values.reshape(-1,1), df['value2'].values.reshape(-1,1)


knn = KNeighborsClassifier(n_neighbors=2)
knn.fit(X_train, y_train.ravel())
knn.score(X_train, y_train)


print(knn.predict([[0.7]]))

我有一个错误:ValueError:预期为2D数组,改为1D数组:array=[0.0638073 0.36326285 0.83634432]。@MartinBouhier我已更新我的答案以解决您的错误。