I have a largar dataset which looks like the picture below, which also contains column "Month" and "Year". I try to use Linear Regression model to precit the total number of victims per month, but I don't know how to get the total number victimsDatafram
from sklearn.linear_model import LinearRegression
reg = LinearRegression()
reg.fit(df_pre[[]],df_pre["Year"]) #don't know how to fit the data in here.
Appreciate help!
I try to fit Vict Age and Month, but I got wrong answer. And I try to create a new datafram which contains only month and total victim, then the fit will have different size.
The concept behind fitting data to the model is:
Since, I couldn't preview your dataset properly, here is a simple example on how to fit data and predict with
LinearRegression
.Let say we have small dataset of
x_1
,x_2
,y
wherex_1
andx_2
are the features (inputs to the model) whiley
is the target (what we want to predict).Our dataset:
Full code
Note that we are using this simple equation
y = (1 * x_1) + (2 * x_2) + 3
and if you should passx_1 = 3
andx_2 = 5
to the equation,y = 16
which means our model works fine.