Click here to Skip to main content
15,867,765 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
My assignment is to predict the total cases for next 3 to 5 months in 2021. So my lecturer told me to use logistic regression, decision tree and random forest. As far I know these three method is for classification. But is there any possible to use these three method to predict for unlabeled data? how can use date with sequence to train?

What I have tried:

Python
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
import datetime as dt
from sklearn.linear_model import LogisticRegression

df = pd.read_csv('https://raw.githubusercontent.com/sahdan96/covid19/main/owid-covid-data.csv')
my_case = df[df['location']=='Malaysia'].reset_index()

my_case['date'] = pd.to_datetime(my_case['date'], format="%Y-%m-%d")
my_case['date'] = my_case['date'].map(dt.datetime.toordinal)

x_train, x_test, y_train, y_test = train_test_split(my_case['date'], my_case['total_cases'], test_size=0.2)
model = LogisticRegression()

newX =np.array(x_train).reshape(-1,1)
newY =np.array(y_train).reshape(-1,1)
newX_test = np.array(x_test).reshape(-1,1)
newY_test =np.array(y_test).reshape(-1,1)

model.fit(newX, newY)

pred =model.predict(newX_test)
from sklearn.metrics import accuracy_score
acc = accuracy_score(newY_test,pred)
print(acc)
Posted
Updated 11-Jan-21 4:14am
v2
Comments
Sandeep Mewara 11-Jan-21 3:24am    
What all data you have? Just the date and no of cases each day? OR additional feautres?
Mugiwara Luffy 11-Jan-21 3:32am    
yeah. just two of them as x and y

1 solution

You're "curve fitting", then "forecasting" with the derived function; and there isn't much to "classify" other than (maybe) Friday is a "better" day than Monday, etc.

https://en.wikipedia.org/wiki/Curve_fitting
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900