Revenue Prediction Neural Network Python

Revenue Prediction Neural Network Python



I'm trying to create a neural network. I cut a because I have more than 1000 lists.
I saw a lot of tutorials but I need some help:


a



Can I use a list of list as my database instead of 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




1 Answer
1



Yes, yes you can. This becomes trivial with the pandas library. First you need to import pandas, then with the following code you can convert your list of lists into a pandas dataframe:


import pandas


df = DataFrame(a, columns=headers)



then you can set up the training set with:


X_train, y_train = df['value1'], df['value2']



Your value2 column is expected to contain labels for the classifier to work with. Labels cannot be of type float for KNN classifiers, so simply adjusting them to integers will solve the problem.


value2


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]]))






I have an error: ValueError: Expected 2D array, got 1D array instead: array=[0.0638073 0.36326285 0.83634432].

– Martin Bouhier
Sep 6 '18 at 0:57


ValueError: Expected 2D array, got 1D array instead: array=[0.0638073 0.36326285 0.83634432].






@MartinBouhier I've updated my answer to resolve your error.

– Philip DiSarro
Sep 6 '18 at 18:53



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế