Python Forum
How to predict with date as input for DecisionTreeRegressor
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Which network architecture should be chosen to predict disease severity? AlekseyPython 2 253 Aug-21-2021, 07:12 PM
Last Post: jefsummers
  How to predict output in a regression problem? Rezaafz 1 629 Apr-03-2021, 04:16 PM
Last Post: jefsummers
  Keras.Predict into Dataframe Finpyth 13 3,310 Aug-31-2020, 07:22 AM
Last Post: hussainmujtaba
  Analyze, predict the next step in a sequence. Antonio0608 0 828 Jul-23-2020, 05:53 PM
Last Post: Antonio0608
  Error When Using sklearn Predict Function firebird 0 860 Mar-21-2020, 04:34 PM
Last Post: firebird
  replace nan values by mean group by date.year, date.month wissam1974 5 4,370 Feb-19-2020, 06:25 PM
Last Post: AnkitGupta
  Predict Longitude and Latitude Using Python vibeandvisualize 1 924 Dec-27-2019, 12:10 PM
Last Post: Larz60+
  Trying to Pass date to pandas search from input prompt curranjohn46 1 926 Oct-10-2019, 10:01 AM
Last Post: curranjohn46
  Finding date count from a list of date range in pandas trillerducas72 0 1,485 May-24-2018, 02:30 AM
Last Post: trillerducas72
  Can someone explain how does svr_rbf.predict(dates) work? j2ee 0 2,323 Feb-22-2018, 06:50 PM
Last Post: j2ee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020