I want to predict the products which a person will buy, by looking at the products which they bought earlier.
my dataframe has 'overall', 'reviewerID', 'asin' , 'brand'.
overall - rating of the product
reviewerID - ID of the reviewer
asin - ID of the product
brand - brand name
My code is as follows:
import pandas as pd
import numpy as np
first = pd.read_pickle("customers_more_than_one_product.pkl")
data = pd.read_pickle("customers_more_than_one_product.pkl")
data['reviewerID'] = data["reviewerID"].rank(method='dense').astype(int)
data['asin'] = data["asin"].rank(method='dense').astype(int)
data['brand'] = data["brand"].rank(method='dense').astype(int)
data = data.drop(["reviewTime","reviewText","title"],1)
My dataframe is this.
I assigned 3 columns which are 'overall', 'reviewerID', 'brand' to X, and 1 column which is 'asin' to y below:
X= data["reviewerID"].values
x1=data["overall"].values
x2=data["brand"].values
X=np.vstack(X, x1,x2).T
y= data["asin"].values
I splitted data such that randomly selected 70% tuples are used for training while 30% tuples are used for testing.
from sklearn.model_selection import train_test_split
X_train,X_test , y_train , y_test = train_test_split(X, y, test_size=0.3, random_state=1)
I used Sklearn library for MLP Classsifier.
from sklearn.neural_network import MLPClassifier
import time
training_time_avg=0
error_cost_avg=0
i=0
I applied single-layer perceptron network solver to handle my data 10 times. Also I tried to fit my training datas and calculate the time by using 'time':
while i < 10:
clf= MLPClassifier(hidden_layer_sizes=(), max_iter=100)
start = time.time()
clf.fit(X_train, y_train)
stop = time.time()
accuracy=clf.score(X_test, y_test)
error_rate = 1 - accuracy
training_time_avg = training_time_avg + (stop - start)
error_cost_avg=error_cost_avg + error_rate
i=i+1
I printed average training time and error cost my result.
print("max_iter:",100)
print("\nTraining Time Average (in ms): ",(training_time_avg/10))
print("Error Average (cost): ", (error_cost_avg/10))
However, my code keeps run, although I got no errors when I run the code. It's like endless loop. I checked Variable Explorer screen on Spyder, everything worked until clf.fit(X_train, y_train) line.
Is there anyone who can help me to fix this problem? Or using which method can I reach prediction of the products which a person will buy, by looking at the products which they bought earlier?