Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to predict with date as input for DecisionTreeRegressor
#1
Hi Forum,

How to predict with date as input for DecisionTreeRegressor model?

source: student_mark_result_dec_hist.csv

name day subject percentage
john 12/1/2019 maths 30
john 12/2/2019 maths 40
john 12/3/2019 maths 33
john 12/4/2019 maths 32
john 12/5/2019 maths 31
john 12/6/2019 maths 38
john 12/7/2019 maths 35
john 12/8/2019 maths 38
john 12/9/2019 maths 39
john 12/10/2019 maths 55
john 12/11/2019 maths 65
john 12/12/2019 maths 68
john 12/13/2019 maths 62
john 12/14/2019 maths 70
john 12/15/2019 maths 64
john 12/16/2019 maths 82
john 12/17/2019 maths 80
john 12/18/2019 maths 55
john 12/19/2019 maths 68
john 12/20/2019 maths 79
john 12/21/2019 maths 88
john 12/22/2019 maths 87
john 12/23/2019 maths 80
john 12/24/2019 maths 75


Now, i want to predict for 12/25/2019 and 11/30/2019 marks for subject-maths for name -john, Any ideas?
I was trying with below, but i doubt that's absolutely incorrect,


import pandas as pd
#import numpy as np
from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn import preprocessing


raw_data=pd.read_csv('student_mark_result_dec_hist.csv',index_col=False)
blankIndex=[''] * len(raw_data)
raw_data.index=blankIndex

le = preprocessing.LabelEncoder()

for column_name in raw_data.columns:
	if raw_data[column_name].dtype == object:
		raw_data[column_name] = le.fit_transform(raw_data[column_name])
		le_name_mapping = dict(zip(le.classes_, le.transform(le.classes_)))
		print(le_name_mapping)
		
	else:
		pass
print('---->', raw_data[:])

X=raw_data[['name','day','subject']]
y=raw_data['percentage']

model=DecisionTreeRegressor()
model.fit(X,y)

predictions=model.predict([  [0,24,0], [0,-1,0]  ])
print(predictions)

#here, i am not sure if [0.24.0],[0,-1,0] points to date 12/25/2019 and 11/30/2019, Any ideas?
Best Regards,
Sandeep

GANGA SANDEEP KUMAR
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  replace nan values by mean group by date.year, date.month wissam1974 5 1,163 Feb-19-2020, 06:25 PM
Last Post: AnkitGupta
  Predict Longitude and Latitude Using Python vibeandvisualize 1 175 Dec-27-2019, 12:10 PM
Last Post: Larz60+
  Trying to Pass date to pandas search from input prompt curranjohn46 1 218 Oct-10-2019, 10:01 AM
Last Post: curranjohn46
  Finding date count from a list of date range in pandas trillerducas72 0 788 May-24-2018, 02:30 AM
Last Post: trillerducas72
  Can someone explain how does svr_rbf.predict(dates) work? j2ee 0 1,242 Feb-22-2018, 06:50 PM
Last Post: j2ee
  Model.predict() always returning the same value of 1 for opencv nastyheatnor 0 2,274 Dec-14-2017, 08:20 AM
Last Post: nastyheatnor
  how to predict next value taking in account several variables? drogontargaryen 2 1,505 Aug-23-2017, 02:16 AM
Last Post: ichabod801

Forum Jump:


Users browsing this thread: 1 Guest(s)