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 nuclear 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[['NUETP']][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 NUETP 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('NuclearPreds.csv', encoding='utf-8', index=False)


49
     Year         AK   AL   AR           AZ           CA            CO   CT  \
0  2015.0  10.515044  0.0  0.0   657.836108  6585.553266   8288.731597  0.0   
1  2016.0  11.166682  0.0  0.0   879.139468  6538.859714  10079.725772  0.0   
2  2017.0  16.408535  0.0  0.0  1150.539818  7060.181502  12100.651341  0.0   
3  2018.0  19.251201  0.0  0.0  1484.427320  7699.009108  14502.084504  0.0   
4  2019.0  22.336940  0.0  0.0  1883.640266  8143.807623  17213.315526  0.0   
5  2020.0  24.370005  0.0  0.0  2373.383323  8622.665452  20407.826030  0.0   

         DE   FL     ...                 SD         TN            TX  \
0  0.352990  0.0     ...        3492.217868  15.354359  30784.406376   
1  0.658644  0.0     ...        4417.190191  10.440483  32064.267091   
2  0.930583  0.0     ...        5580.434239   3.712558  32483.289134   
3  1.137113  0.0     ...        7004.949707   0.000000  33119.056536   
4  1.287948  0.0     ...        8766.412924   0.000000  33543.518592   
5  1.432348  0.0     ...       10943.770954   0.000000  34062.365911   

           UT   VA         VT           WA           WI          WV  \
0  329.294242  0.0  20.797697  4076.941195  2542.827111  366.796411   
1  344.007525  0.0  32.585696  4667.701675  2947.970169  427.264879   
2  368.763347  0.0  24.593795  5284.517154  3404.938582  504.102394   
3  389.236667  0.0  34.369950  5914.492800  3939.677131  567.077612   
4  407.400369  0.0  35.961895  6424.901512  4563.754777  608.941382   
5  426.511761  0.0  35.899090  7070.548149  5273.807268  650.899933   

            WY  
0  5726.842096  
1  6182.218555  
2  6601.611815  
3  7012.994886  
4  7427.287803  
5  7742.488016  

[6 rows x 50 columns]

In [ ]: