2
$\begingroup$

How to predict the per capita income of Pakistan in 2020 by using linear regression model in Python. The training data is:

Year    Income
1970    3399.299037
1971    3768.297935
1972    4251.175484
1973    4804.463248
1974    5576.514583
1975    5998.144346
1976    7062.131392
1977    7100.12617
1978    7247.967035
1979    7602.912681
1980    8355.96812
1981    9434.390652
1982    9619.438377
1983    10416.53659
1984    10790.32872
1985    11018.95585
1986    11482.89153
1987    12974.80662
1988    15080.28345
1989    16426.72548
1990    16838.6732
1991    17266.09769
1992    16412.08309
1993    15875.58673
1994    15755.82027
1995    16369.31725
1996    16699.82668
1997    17310.75775
1998    16622.67187
1999    17581.02414
2000    18987.38241
2001    18601.39724
2002    19232.17556
2003    22739.42628
2004    25719.14715
2005    29198.05569
2006    32738.2629
2007    36144.48122
2008    37446.48609
2009    32755.17682
2010    38420.52289
2011    42334.71121
2012    42665.25597
2013    42676.46837
2014    41039.8936
2015    35175.18898
2016    34229.19363
$\endgroup$
  • $\begingroup$ Welcome to DS.Stack Exchange! You are not really asking a question. What issues are you having with this task? $\endgroup$ – Simon Larsson Apr 24 '19 at 7:35
  • $\begingroup$ Actually give me a task. so i ask this question. Simon Larsson $\endgroup$ – Shamoon Ahmad Apr 24 '19 at 7:39
  • $\begingroup$ Try looking at the example here. Replacing X with your years and y with your yearly incomes : scikit-learn.org/stable/modules/generated/… $\endgroup$ – Simon Larsson Apr 24 '19 at 8:07
3
$\begingroup$

Try:

from sklearn.linear_model import LinearRegression
import numpy as np
regression_model = LinearRegression()
Year = np.array([[1970], [1971], [1972]]) #your data
Income = np.array([3399.299037, 3768.297935, 4251.175484]) #your data
regression_model.fit(Year, Income)
regression_model.predict([[1973]]) #make predictions
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks a lot .............................................................................. $\endgroup$ – Shamoon Ahmad Apr 25 '19 at 9:29
0
$\begingroup$

Try following this tutorial. https://towardsdatascience.com/linear-regression-using-python-b136c91bf0a2

Here years will be your input variable and income will be the target you are trying to predict. You can use R^2 as an evaluation measure to see how well your model is predicting. Keep the last 10 years for testing to check how well it performs on test set

| improve this answer | |
$\endgroup$
0
$\begingroup$

try like this

import pandas result = pandas.read_csv('C:\Users\Desktop\teri.csv') print(result) regression_model.fit(Year, Income) regression_model.predict([[2019]])

Out[26]: array([32536.51562343])

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.