In [1]:
# import libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn import linear_model
from sklearn.model_selection import train_test_split

In [2]:
# read data
data = pd.read_csv("CA.csv")
year1 = data[['Year']][:44]
#print(year1.shape)
year2 = data[['Year']][-11:]

# predict Wind for future
year3 = year2 = data[['Year']][-6:]
year3 = year3.set_index([[0, 1, 2, 3, 4, 5]])

statelist=["AK","AL","AR","AZ","CA","CO","CT","DE","FL","GA","IA","ID","IL","IN","KS","KY","LA","MA","MD","ME","MI","MN","MO","MS","MT","NC","ND","NE","NH","NJ","NM","NV","NY","OH","OK","OR","PA","RI","SC","SD","TN","TX","UT","VA","VT","WA","WI","WV","WY"]
print(len(statelist))

future = year3
# do ridge regression on train data

for i in range(49):
    data = pd.read_csv('%s.csv' % (statelist[i]))
    
    year1 = data[['Year']][:44]
    #print(year1.shape)
    year2 = data[['Year']][-11:]
    # Split data for train and test
    #print(i)
    all_x = data[['GDP','CLPRB','EMFDB','ENPRP','NGMPB','PAPRB','PCP','ZNDX','Nominal Price', 'Inflation Adjusted Price']][0:55]
    all_y = data[['WYTCP']][0:55]
    train_x, test_x, train_y, test_y = train_test_split(all_x, all_y, test_size=0.2)
    regr2 = linear_model.Ridge(alpha = 0.75)
    regr2.fit(train_x, train_y)
    # predict WYTCP for future
    #year3 = data[['Year']][-6:]
    #year3 = year3.set_index([[0, 1, 2, 3, 4, 5]])
    #print(year3)
    future_x = data[['GDP','CLPRB','EMFDB','ENPRP','NGMPB','PAPRB','PCP','ZNDX','Nominal Price', 'Inflation Adjusted Price']][-6:]
    pred = pd.DataFrame(regr2.predict(future_x).clip(min=0))
    pred.columns = [statelist[i]]
    #print(pred)
    future = pd.concat([future, pred], axis=1)
    #print(future)
print(future)

# output to csv
future.to_csv('WindPreds.csv', encoding='utf-8', index=False)


49
     Year   AK            AL           AR            AZ            CA   CO  \
0  2015.0  0.0  30830.873678  8407.004655  50888.882997  41136.625744  0.0   
1  2016.0  0.0  32887.151123  3229.993275  53946.927366  39976.353424  0.0   
2  2017.0  0.0  32801.954859     0.000000  57990.737679  42686.196015  0.0   
3  2018.0  0.0  33209.543963     0.000000  63131.161375  42140.851188  0.0   
4  2019.0  0.0  34041.863130     0.000000  68807.979214  41843.585874  0.0   
5  2020.0  0.0  35052.499760     0.000000  75628.523349  40892.412003  0.0   

             CT   DE            FL ...    SD            TN            TX   UT  \
0  18187.830798  0.0  37243.076907 ...   0.0  26773.396288  48779.678361  0.0   
1  17921.159713  0.0  36377.149434 ...   0.0  26805.842395  51899.688369  0.0   
2  18251.827587  0.0  36109.336005 ...   0.0  30607.294748  51874.730203  0.0   
3  18317.047879  0.0  36216.991144 ...   0.0  36987.259891  54109.687047  0.0   
4  18135.563796  0.0  36244.134630 ...   0.0  44438.560891  55017.957223  0.0   
5  18123.900788  0.0  36100.321829 ...   0.0  54854.850024  57350.503947  0.0   

             VA           VT           WA            WI   WV   WY  
0  34003.867820  5783.494011  6049.133851  10814.184938  0.0  0.0  
1  34710.118126  5743.539844  5820.435072  12974.954030  0.0  0.0  
2  34828.005737  5729.139149  5650.449189  14487.016278  0.0  0.0  
3  35158.178283  5555.700549  5389.055667  18687.084535  0.0  0.0  
4  36006.703409  5629.323064  5108.336106  23262.484540  0.0  0.0  
5  36863.525493  5666.702156  4719.384521  28945.227691  0.0  0.0  

[6 rows x 50 columns]

In [ ]:


In [ ]: