├── .gitattributes ├── .gitignore ├── Module 1 ├── Chapter 2 │ └── B01782_Ch02_Codes.txt ├── Chapter 3 │ └── Chapter 3 codes.txt ├── Chapter 5 │ └── CHapter 5 Codes.txt ├── Chapter 6 │ └── Chapter 6 Codes.txt ├── Chapter 7 │ └── Chapter 7 Codes.txt ├── Read ME.txt └── Software list.pdf ├── Module 2 └── MasteringPredictiveAnalyticswithPython_Code │ ├── B04881_02_code │ ├── Africa_SHP.zip │ ├── Africa_SHP │ │ ├── Africa.dbf │ │ ├── Africa.shp │ │ └── Africa.shx │ ├── Africa_populations.tsv │ ├── B04881_chapter02_code01.ipynb │ ├── B04881_chapter02_code02.ipynb │ ├── B04881_chapter02_code03.ipynb │ ├── car_crashes.csv │ ├── movies.csv │ └── oil.csv │ ├── B04881_03_code │ └── B04881_chapter03_code │ │ └── B04881_chapter03_code │ │ ├── B04881_chapter03_code01.ipynb │ │ ├── B04881_chapter03_code02.ipynb │ │ ├── Papers.csv │ │ ├── kmeans.txt │ │ └── kmeans2.txt │ ├── B04881_04_code │ ├── B04881_chapter04_code01.ipynb │ ├── B04881_chapter04_code02.ipynb │ └── OnlineNewsPopularity.csv │ ├── B04881_07_code │ ├── B04481_chapter_07_code_01.ipynb │ └── MNIST_data │ │ ├── t10k-images-idx3-ubyte.gz │ │ ├── t10k-labels-idx1-ubyte.gz │ │ ├── train-images-idx3-ubyte.gz │ │ └── train-labels-idx1-ubyte.gz │ ├── B04881_08_code │ ├── B04881_chapter_08_code_01.ipynb │ ├── B04881_chapter_08_code_02.ipynb │ ├── LogisticRegression.py │ ├── Titanic.csv │ ├── dataparser.py │ ├── model_server.py │ ├── modelfactory.py │ ├── modelservice.py │ └── parameters.json │ ├── README.txt │ └── SoftwareList.pdf └── Readme.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /Module 1/Chapter 2/B01782_Ch02_Codes.txt: -------------------------------------------------------------------------------- 1 | 1. # Importing the dataset 2 | import pandas as pd 3 | data = pd.read_csv('E:/Personal/Learning/Datasets/Book/titanic3.csv') 4 | 5 | 6 | 2. # Passing the directory address and filename as variables 7 | import pandas as pd 8 | path = 'E:/Personal/Learning/Datasets/Book' 9 | filename = 'titanic3.csv' 10 | fullpath = path+'/'+filename 11 | data = pd.read_csv(fullpath) 12 | 13 | 3. # Reading a .txt dataset with a comma delimiter 14 | import pandas as pd 15 | data = read_csv('E:/Personal/Learning/Datasets/Book/Customer Churn Model.txt') 16 | 17 | 18 | 4. # Specifying the column names of dataset from a list 19 | import pandas as pd 20 | data = pd.read_csv('E:/Personal/Learning/Datasets/Book/Customer Churn Model.txt') 21 | data.columns.values 22 | data_columns = pd.read_csv('E:/Personal/Learning/Predictive Modeling Book/Book Datasets/Customer Churn Columns.csv') 23 | data_column_list = data_columns['Column_Names'].tolist() 24 | data=pd.read_csv('E:/Personal/Learning/Predictive Modeling Book/Book Datasets/Customer Churn Model.txt',header=None,names=data_column_list) 25 | data.columns.values 26 | 27 | 28 | 5. # Opening the dataset using Open method 29 | data=open('E:/Personal/Learning/Predictive Modeling Book/Book Datasets/Customer Churn Model.txt','r') 30 | cols=data.next().strip().split(',') 31 | no_cols=len(data.next().strip().split(',')) 32 | 33 | counter=0 34 | main_dict={} 35 | for col in cols: 36 | main_dict[col]=[] 37 | 38 | for line in data: 39 | values = line.strip().split(',') 40 | for i in range(len(cols)): 41 | main_dict[cols[i]].append(values[i]) 42 | counter += 1 43 | 44 | print "The dataset has %d rows and %d columns" % (counter,no_cols) 45 | 46 | import pandas as pd 47 | df=pd.DataFrame(main_dict) 48 | print df.head(5) 49 | 50 | 51 | 52 | 6. # Changing delimiter of a dataset 53 | 54 | infile='E:/Personal/Learning/Datasets/Book/Customer Churn Model.txt' 55 | outfile='E:/Personal/Learning/Datasets/Book/Tab Customer Churn Model.txt' 56 | with open(infile) as infile1: 57 | with open(outfile,'w') as outfile1: 58 | for line in infile1: 59 | fields=line.split(',') 60 | outfile1.write('/t'.join(fields)) 61 | 62 | 63 | 7. # Importing data from a URL 64 | 65 | import pandas as pd 66 | medal_data=pd.read_csv('http://winterolympicsmedals.com/medals.csv') 67 | 68 | 69 | import csv 70 | import urllib2 71 | 72 | url='http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data’ 73 | response=urllib2.urlopen(url) 74 | cr=csv.reader(response) 75 | 76 | for rows in cr: 77 | print rows 78 | 79 | 8. # Reading from an .xls or .xlsx file 80 | 81 | import pandas as pd 82 | data=pd.read_excel('E:/Personal/Learning/Predictive Modeling Book/Book Datasets/titanic3.xls','titanic3') 83 | 84 | import pandas as pd 85 | data=pd.read_excel('E:/Personal/Learning/Predictive Modeling Book/Book Datasets/titanic3.xlsx','titanic3') 86 | 87 | 9. # Writing to a csv or an excel file 88 | 89 | df.to_csv(‘E:/Personal/Learning/Predictive Modeling Book/Book Datasets/Customer Churn Model.csv’ 90 | 91 | 92 | df.to_excel(‘E:/Personal/Learning/Predictive Modeling Book/Book Datasets/Customer Churn Model.csv’ 93 | 94 | 95 | 10. # Summary/DImensions/Structure 96 | 97 | data.head() 98 | data.shape 99 | data.columns.values 100 | data.describe() 101 | data.dtypes 102 | 103 | 104 | 11. # Handling missing Values 105 | 106 | pd.isnull(data[‘body’]) 107 | pd.notnull(data['body']) 108 | pd.isnull(data['body']).values.ravel().sum() 109 | pd.nottnull(data['body']).values.ravel().sum() 110 | data.dropna(axis=0,how='all') 111 | data.dropna(axis=0,how='any') 112 | data.fillna(0) 113 | data.fillna(‘missing’) 114 | data[‘body’].fillna(0) 115 | data['body'] 116 | data['age'] 117 | data['age'].fillna(data['age'].mean()) 118 | data['age'].fillna(method='ffill') 119 | data['age'].fillna(method='backfill') 120 | 121 | 122 | 12. # Dummy Variable 123 | 124 | dummy_sex=pd.get_dummies(data['sex'],prefix='sex') 125 | column_name=data.columns.values.tolist() 126 | column_name.remove('sex') 127 | data[column_name].join(dummy_sex) 128 | 129 | 13. # Basic Scatter Plot 130 | 131 | import pandas as pd 132 | data=pd.read_csv('E:/Personal/Learning/Predictive Modeling Book/Book Datasets/Customer Churn Model.txt') 133 | data.plot(kind='scatter',x='Day Mins',y='Day Charge') 134 | plt.show() 135 | 136 | 14. # Scatter Plots in a 2x2 panel 137 | 138 | import pandas as pd 139 | import matplotlib.pyplot as plt 140 | data=pd.read_csv('E:/Personal/Learning/Predictive Modeling Book/Book Datasets/Customer Churn Model.txt') 141 | data=pd.read_csv('C:/python_data/Customer Churn Model.txt') 142 | figure,axs = plt.subplots(2, 2,sharey=True,sharex=True) 143 | data.plot(kind='scatter',x='Day Mins',y='Day Charge',ax=axs[0][0]) 144 | data.plot(kind='scatter',x='Night Mins',y='Night Charge',ax=axs[0][1]) 145 | data.plot(kind='scatter',x='Day Calls',y='Day Charge',ax=axs[1][0]) 146 | data.plot(kind='scatter',x='Night Calls',y='Night Charge',ax=axs[1][1]) 147 | plt.show() 148 | 149 | 15. # Plotting a Histogram 150 | 151 | import matplotlib.pyplot as plt 152 | plt.hist(data['Day Calls'],bins=8) 153 | plt.xlabel('Day Calls Value') 154 | plt.ylabel('Frequency') 155 | plt.title('Frequency of Day Calls') 156 | plt.show() 157 | 158 | 16. # Plotting a Box Plot 159 | 160 | import matplotlib.pyplot as plt 161 | plt.boxplot(data['Day Calls']) 162 | plt.ylabel('Day Calls') 163 | plt.title('Box Plot of Day Calls') 164 | plt.show() 165 | 166 | -------------------------------------------------------------------------------- /Module 1/Chapter 3/Chapter 3 codes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Advanced-Predictive-Analytics/eda343c48e58b613c28a21a35155f213f4b1771a/Module 1/Chapter 3/Chapter 3 codes.txt -------------------------------------------------------------------------------- /Module 1/Chapter 5/CHapter 5 Codes.txt: -------------------------------------------------------------------------------- 1 | # Step 1: defining the likelihood function 2 | def likelihood(y,pi): 3 | import numpy as np 4 | ll=1 5 | ll_in=range(1,len(y)+1) 6 | for i in range(len(y)): 7 | ll_in[i]=np.where(y[i]==1,pi[i],(1-pi[i])) 8 | ll=ll*ll_in[i] 9 | return ll 10 | 11 | # Step 2: calculating probability for each observation 12 | def logitprob(X,beta): 13 | import numpy as np 14 | rows=np.shape(X)[0] 15 | cols=np.shape(X)[1] 16 | pi=range(1,rows+1) 17 | expon=range(1,rows+1) 18 | for i in range(rows): 19 | expon[i]=0 20 | for j in range(cols): 21 | ex=X[i][j]*beta[j] 22 | expon[i]=ex+expon[i] 23 | with np.errstate(divide='ignore', invalid='ignore'): 24 | pi[i]=np.exp(expon[i])/(1+np.exp(expon[i])) 25 | return pi 26 | 27 | # Step 3: Calculate the W diagonal matrix 28 | def findW(pi): 29 | import numpy as np 30 | W=np.zeros(len(pi)*len(pi)).reshape(len(pi),len(pi)) 31 | for i in range(len(pi)): 32 | print i 33 | W[i,i]=pi[i]*(1-pi[i]) 34 | W[i,i].astype(float) 35 | return W 36 | 37 | # Step 4: defining the logistic function 38 | def logistic(X,Y,limit): 39 | import numpy as np 40 | from numpy import linalg 41 | nrow=np.shape(X)[0] 42 | bias=np.ones(nrow).reshape(nrow,1) 43 | X_new=np.append(X,bias,axis=1) 44 | ncol=np.shape(X_new)[1] 45 | beta=np.zeros(ncol).reshape(ncol,1) 46 | root_diff=np.array(range(1,ncol+1)).reshape(ncol,1) 47 | iter_i=10000 48 | while(iter_i>limit): 49 | print iter_i, limit 50 | pi=logitprob(X_new,beta) 51 | print pi 52 | W=findW(pi) 53 | print W 54 | print X_new 55 | print (Y-np.transpose(pi)) 56 | print np.array((linalg.inv(np.matrix(np.transpose(X_new))*np.matrix(W)*np.matrix(X_new)))*(np.transpose(np.matrix(X_new))*np.matrix(Y-np.transpose(pi)).transpose())) 57 | print beta 58 | print type(np.matrix(np.transpose(Y-np.transpose(pi)))) 59 | print np.matrix(Y-np.transpose(pi)).transpose().shape 60 | print np.matrix(np.transpose(X_new)).shape 61 | root_diff=np.array((linalg.inv(np.matrix(np.transpose(X_new))*np.matrix(W)*np.matrix(X_new)))*(np.transpose(np.matrix(X_new))*np.matrix(Y-np.transpose(pi)).transpose())) 62 | beta=beta+root_diff 63 | iter_i=np.sum(root_diff*root_diff) 64 | ll=likelihood(Y,pi) 65 | print beta 66 | print beta.shape 67 | return beta 68 | 69 | # Testing the model 70 | import numpy as np 71 | X=np.array(range(10)).reshape(10,1) 72 | Y=[0,0,0,0,1,0,1,0,1,1] 73 | bias=np.ones(10).reshape(10,1) 74 | X_new=np.append(X,bias,axis=1) 75 | 76 | 77 | # Running logistic Regression using our function 78 | a=logistic(X,Y,0.000000001) 79 | ll=likelihood(Y,logitprob(X,a)) 80 | 81 | Coefficient of X = 0.66 , Intercept = -3.69 82 | 83 | # From stasmodel.api 84 | import statsmodels.api as sm 85 | logit_model=sm.Logit(Y,X_new) 86 | result=logit_model.fit() 87 | print result.summary() 88 | 89 | Coefficient of X = 0.66 , Intercept = -3.69 90 | 91 | 92 | 93 | # Creating the Contingency Table 94 | import pandas as pd 95 | df=pd.read_csv('E:/Personal/Learning/Predictive Modeling Book/Book Datasets/Logistic Regression/Gender Purchase.csv') 96 | df.head() 97 | 98 | contingency_table=pd.crosstab(df['Gender'],df['Purchase']) 99 | contingency_table 100 | 101 | contingency_table.astype('float').div(contingency_table.sum(axis=1),axis=0) 102 | 103 | 104 | # Importing the dataset 105 | import pandas as pd 106 | bank=pd.read_csv('E:/Personal/Learning/Predictive Modeling Book/Book Datasets/Logistic Regression/bank.csv',sep=';') 107 | bank.head() 108 | 109 | 110 | # Processing the data 111 | bank['y']=(bank['y']=='yes').astype(int) 112 | 113 | import numpy as np 114 | bank['education']=np.where(bank['education'] =='basic.9y', 'Basic', bank['education']) 115 | bank['education']=np.where(bank['education'] =='basic.6y', 'Basic', bank['education']) 116 | bank['education']=np.where(bank['education'] =='basic.4y', 'Basic', bank['education']) 117 | bank['education']=np.where(bank['education'] =='university.degree', 'University Degree', bank['education']) 118 | bank['education']=np.where(bank['education'] =='professional.course', 'Professional Course', bank['education']) 119 | bank['education']=np.where(bank['education'] =='high.school', 'High School', bank['education']) 120 | bank['education']=np.where(bank['education'] =='illiterate', 'Illiterate', bank['education']) 121 | bank['education']=np.where(bank['education'] =='unknown', 'Unknown', bank['education']) 122 | 123 | # Data Exploration 124 | bank['y'].value_counts() 125 | bank.groupby('y').mean() 126 | bank.groupby('education').mean() 127 | 128 | # Data Visualisation 129 | 130 | %matplotlib inline 131 | pd.crosstab(bank.education,bank.y).plot(kind='bar') 132 | plt.title('Purchase Frequency for Education Level') 133 | plt.xlabel('Education') 134 | plt.ylabel('Frequency of Purchase') 135 | 136 | table=pd.crosstab(bank.marital,bank.y) 137 | table.div(table.sum(1).astype(float), axis=0).plot(kind='bar', stacked=True) 138 | plt.title('Stacked Bar Chart of Marital Status vs Purchase') 139 | plt.xlabel('Marital Status') 140 | plt.ylabel('Proportion of Customers') 141 | 142 | %matplotlib inline 143 | import matplotlib.pyplot as plt 144 | pd.crosstab(bank.day_of_week,bank.y).plot(kind='bar') 145 | plt.title('Purchase Frequency for Day of Week') 146 | plt.xlabel('Day of Week') 147 | plt.ylabel('Frequency of Purchase') 148 | 149 | import matplotlib.pyplot as plt 150 | bank.age.hist() 151 | plt.title('Histogram of Age') 152 | plt.xlabel('Age') 153 | plt.ylabel('Frequency') 154 | 155 | # Creating dummy variables for categorical variables 156 | cat_vars=['job','marital','education','default','housing','loan','contact','month','day_of_week','poutcome'] 157 | for var in cat_vars: 158 | cat_list='var'+'_'+var 159 | cat_list = pd.get_dummies(bank[var], prefix=var) 160 | bank1=bank.join(cat_list) 161 | bank=bank1 162 | 163 | cat_vars=['job','marital','education','default','housing','loan','contact','month','day_of_week','poutcome'] 164 | bank_vars=bank.columns.values.tolist() 165 | to_keep=[i for i in bank_vars if i not in cat_vars] 166 | 167 | bank_final=bank[to_keep] 168 | bank_final.columns.values 169 | 170 | bank_final_vars=bank_final.columns.values.tolist() 171 | Y=['y'] 172 | X=[i for i in bank_final_vars if i not in Y ] 173 | 174 | 175 | # Feature Selection 176 | 177 | from sklearn import datasets 178 | from sklearn.feature_selection import RFE 179 | from sklearn.linear_model import LogisticRegression 180 | 181 | model = LogisticRegression() 182 | 183 | rfe = RFE(model, 12) 184 | rfe = rfe.fit(bank_final[X],bank_final[Y] ) 185 | 186 | print(rfe.support_) 187 | print(rfe.ranking_) 188 | 189 | 190 | cols=['previous', 'euribor3m', 'job_entrepreneur', 'job_self-employed', 'poutcome_success', 'poutcome_failure', 'month_oct', 'month_may', 191 | 'month_mar', 'month_jun', 'month_jul', 'month_dec'] 192 | X=bank_final[cols] 193 | Y=bank_final['y'] 194 | 195 | # Implementing the model 196 | 197 | import statsmodels.api as sm 198 | logit_model=sm.Logit(Y,X) 199 | result=logit_model.fit() 200 | print result.summary() 201 | 202 | from sklearn import linear_model 203 | clf = linear_model.LogisticRegression() 204 | clf.fit(X, Y) 205 | clf.score(X,Y) 206 | 207 | import numpy as np 208 | pd.DataFrame(zip(X.columns, np.transpose(clf.coef_))) 209 | 210 | # Model evaluation and validation 211 | 212 | from sklearn.cross_validation import train_test_split 213 | X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.3, random_state=0) 214 | 215 | from sklearn import linear_model 216 | from sklearn import metrics 217 | clf1 = linear_model.LogisticRegression() 218 | clf1.fit(X_train, Y_train) 219 | 220 | probs = clf1.predict_proba(X_test) 221 | predicted = clf1.predict(X_test) 222 | 223 | import pandas as pd 224 | import numpy as np 225 | prob=probs[:,1] 226 | prob_df=pd.DataFrame(prob) 227 | prob_df['predict']=np.where(prob_df[0]>=0.10,1,0) 228 | prob_df.head() 229 | 230 | print metrics.accuracy_score(Y_test, predicted) 231 | 232 | # Cross Validation 233 | 234 | from sklearn.cross_validation import cross_val_score 235 | scores = cross_val_score(linear_model.LogisticRegression(), X, Y, scoring='accuracy', cv=8) 236 | print scores 237 | print scores.mean() 238 | 239 | 240 | # ROC Curve 241 | 242 | from sklearn.cross_validation import train_test_split 243 | from sklearn import linear_model 244 | from sklearn import metrics 245 | X_train, X_test, Y_train, Y_test = train_test_split(X, Y, test_size=0.3, random_state=0) 246 | clf1 = linear_model.LogisticRegression() 247 | clf1.fit(X_train, Y_train) 248 | probs = clf1.predict_proba(X_test) 249 | 250 | prob=probs[:,1] 251 | prob_df=pd.DataFrame(prob) 252 | prob_df['predict']=np.where(prob_df[0]>=0.05,1,0) 253 | prob_df['actual']=Y_test 254 | prob_df.head() 255 | 256 | confusion_matrix=pd.crosstab(prob_df['actual'],prob_df['predict']) 257 | confusion_matrix 258 | 259 | import matplotlib.pyplot as plt 260 | %matplotlib inline 261 | Sensitivity=[1,0.95,0.87,0.62,0.67,0.59,0.5,0.41,0] 262 | FPR=[1,0.76,0.62,0.23,0.27,0.17,0.12,0.07,0] 263 | plt.plot(FPR,Sensitivity,marker='o',linestyle='--',color='r') 264 | x=[i*0.01 for i in range(100)] 265 | y=[i*0.01 for i in range(100)] 266 | plt.plot(x,y) 267 | plt.xlabel('(1-Specificity)') 268 | plt.ylabel('Sensitivity') 269 | plt.title('ROC Curve') 270 | 271 | from sklearn import metrics 272 | from ggplot import * 273 | prob = clf1.predict_proba(X_test)[:,1] 274 | fpr, sensitivity, _ = metrics.roc_curve(Y_test, prob) 275 | df = pd.DataFrame(dict(fpr=fpr, sensitivity=sensitivity)) 276 | ggplot(df, aes(x='fpr', y='sensitivity')) +\ 277 | geom_line() +\ 278 | geom_abline(linetype='dashed') 279 | auc = metrics.auc(fpr,sensitivity) 280 | 281 | ggplot(df, aes(x='fpr', ymin=0, ymax='sensitivity')) +\ 282 | geom_area(alpha=0.2) +\ 283 | geom_line(aes(y='sensitivity')) +\ 284 | ggtitle("ROC Curve w/ AUC=%s" % str(auc)) 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | -------------------------------------------------------------------------------- /Module 1/Chapter 6/Chapter 6 Codes.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Advanced-Predictive-Analytics/eda343c48e58b613c28a21a35155f213f4b1771a/Module 1/Chapter 6/Chapter 6 Codes.txt -------------------------------------------------------------------------------- /Module 1/Chapter 7/Chapter 7 Codes.txt: -------------------------------------------------------------------------------- 1 | # Importing the iris dataset 2 | 3 | import pandas as pd 4 | data=pd.read_csv('E:/Personal/Learning/Predictive Modeling Book/My Work/Chapter 7/iris.csv') 5 | data.head() 6 | 7 | # Splitting the predictor and target variables 8 | 9 | colnames=data.columns.values.tolist() 10 | predictors=colnames[:4] 11 | target=colnames[4] 12 | 13 | # Splitting the dataset into train and test variables 14 | data['is_train'] = np.random.uniform(0, 1, len(df)) <= .75 15 | train, test = data[data['is_train']==True], data[data['is_train']==False] 16 | 17 | # Creating and fitting a Decision Tree 18 | 19 | dt = DecisionTreeClassifier(criterion='entropy',min_samples_split=20, random_state=99) 20 | dt.fit(train[predictors], train[target]) 21 | 22 | # Predicting the values using the decision tree 23 | 24 | preds=dt.predict(test[predictors]) 25 | pd.crosstab(test['Species'],preds,rownames=['Actual'],colnames=['Predictions']) 26 | 27 | # Visualising the Decision Tree 28 | 29 | from sklearn.tree import export_graphviz 30 | with open('E:/Personal/Learning/Predictive Modeling Book/My Work/Chapter 7/dtree2.dot', 'w') as dotfile: 31 | export_graphviz(dt, out_file = dotfile, feature_names = predictors) 32 | dotfile.close() 33 | 34 | from os import system 35 | system("dot -Tpng /E:/Personal/Learning/Predictive Modeling Book/My Work/Chapter 7/dtree2.dot -o /E:/Personal/Learning/Predictive Modeling Book/My Work/Chapter 7/dtree2.png") 36 | 37 | 38 | # Cross Validating and Pruning the Decision Tree 39 | 40 | X=data[predictors] 41 | Y=data[target] 42 | dt1.fit(X,Y) 43 | dt1 = DecisionTreeClassifier(criterion='entropy',max_depth=5, min_samples_split=20, random_state=99) 44 | 45 | from sklearn.cross_validation import KFold 46 | crossvalidation = KFold(n=X.shape[0], n_folds=10, shuffle=True, random_state=1) 47 | from sklearn.cross_validation import cross_val_score 48 | score = np.mean(cross_val_score(dt1, X, Y, scoring='accuracy', cv=crossvalidation, n_jobs=1)) 49 | score 50 | 51 | # Feature importance of the tree 52 | 53 | dt1.feature_importances_ 54 | 55 | # Importing the Boston dataset 56 | 57 | import pandas as pd 58 | data=pd.read_csv('E:/Personal/Learning/Predictive Modeling Book/My Work/Chapter 7/Boston.csv') 59 | data.head() 60 | 61 | # Preparation for fitting a regression tree 62 | 63 | colnames=data.columns.values.tolist() 64 | predictors=colnames[:13] 65 | target=colnames[13] 66 | X=data[predictors] 67 | Y=data[target] 68 | 69 | # Creating and fitting a regression tree 70 | 71 | from sklearn.tree import DecisionTreeRegressor 72 | regression_tree = DecisionTreeRegressor(min_samples_split=30,min_samples_leaf=10,random_state=0) 73 | regression_tree.fit(X,Y) 74 | 75 | # Comparing actual and the predicted values from the Regression Tree 76 | 77 | reg_tree_pred=regression_tree.predict(data[predictors]) 78 | data['pred']=reg_tree_pred 79 | cols=['pred','medv'] 80 | data[cols] 81 | 82 | #Cross Validating the Regression Tree 83 | 84 | from sklearn.cross_validation import KFold 85 | from sklearn.cross_validation import cross_val_score 86 | import numpy as np 87 | crossvalidation = KFold(n=X.shape[0], n_folds=10,shuffle=True, random_state=1) 88 | score = np.mean(cross_val_score(regression_tree, X, Y,scoring='mean_squared_error', cv=crossvalidation,n_jobs=1)) 89 | score 90 | 91 | # Calculating the feature importance 92 | 93 | regression_tree.feature_importances_ 94 | 95 | # Creating and fitting a Random Forest 96 | 97 | from sklearn.ensemble import RandomForestRegressor 98 | rf = RandomForestRegressor(n_jobs=2,oob_score=True,n_estimators=10) 99 | rf.fit(X,Y) 100 | 101 | # Out of Bag prediction 102 | 103 | rf.oob_prediction_ 104 | 105 | # Comparing actual values with Random Forest predictions 106 | 107 | data['rf_pred']=rf.oob_prediction_ 108 | cols=['rf_pred','medv'] 109 | data[cols].head() 110 | 111 | # Calculating the squared mean error 112 | 113 | data['rf_pred']=rf.oob_prediction_ 114 | data['err']=(data['rf_pred']-data['medv'])**2 115 | sum(data['err'])/506 116 | 117 | # Calculating the oob score 118 | 119 | rf.oob_score_ 120 | 121 | 122 | -------------------------------------------------------------------------------- /Module 1/Read ME.txt: -------------------------------------------------------------------------------- 1 | Chapter 1, 4, 8, 9 does have code files. -------------------------------------------------------------------------------- /Module 1/Software list.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Advanced-Predictive-Analytics/eda343c48e58b613c28a21a35155f213f4b1771a/Module 1/Software list.pdf -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_02_code/Africa_SHP.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Advanced-Predictive-Analytics/eda343c48e58b613c28a21a35155f213f4b1771a/Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_02_code/Africa_SHP.zip -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_02_code/Africa_SHP/Africa.dbf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Advanced-Predictive-Analytics/eda343c48e58b613c28a21a35155f213f4b1771a/Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_02_code/Africa_SHP/Africa.dbf -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_02_code/Africa_SHP/Africa.shp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Advanced-Predictive-Analytics/eda343c48e58b613c28a21a35155f213f4b1771a/Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_02_code/Africa_SHP/Africa.shp -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_02_code/Africa_SHP/Africa.shx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Advanced-Predictive-Analytics/eda343c48e58b613c28a21a35155f213f4b1771a/Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_02_code/Africa_SHP/Africa.shx -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_02_code/Africa_populations.tsv: -------------------------------------------------------------------------------- 1 | Country_Name Population Year_of_Estimate 2 | Nigeria 177,155,760 2014 3 | Ethiopia 96,633,456 2014 4 | Egypt 86,895,096 2014 5 | Congo, Democratic Republic of the 77,433,744 2014 6 | Tanzania 49,639,136 2014 7 | South Africa 48,375,644 2014 8 | Kenya 45,010,056 2014 9 | Algeria 38,813,720 2014 10 | Uganda 35,918,916 2014 11 | Sudan 35,482,232 2014 12 | Morocco 32,987,206 2014 13 | Ghana 25,758,108 2014 14 | Mozambique 24,692,144 2014 15 | Madagascar 23,201,926 2014 16 | Cameroon 23,130,708 2014 17 | Cote d'Ivoire 22,848,944 2014 18 | Angola 19,088,106 2014 19 | Burkina Faso 18,365,124 2014 20 | Niger 17,466,172 2014 21 | Malawi 17,377,468 2014 22 | Mali 16,455,903 2014 23 | Zambia 14,638,505 2014 24 | Zimbabwe 13,771,721 2014 25 | Senegal 13,635,927 2014 26 | Rwanda 12,337,138 2014 27 | Guinea 11,474,383 2014 28 | Chad 11,412,107 2014 29 | Tunisia 10,937,521 2014 30 | Somalia 10,428,043 2014 31 | Burundi 10,395,931 2014 32 | Benin 10,160,556 2014 33 | Togo 7,351,374 2014 34 | Eritrea 6,380,803 2014 35 | Libya 6,244,174 2014 36 | Sierra Leone 5,743,725 2014 37 | Central African Republic 5,277,959 2014 38 | Congo, Republic of the 4,662,446 2014 39 | Liberia 4,092,310 2014 40 | Mauritania 3,516,806 2014 41 | Namibia 2,198,406 2014 42 | Botswana 2,155,784 2014 43 | Lesotho 1,942,008 2014 44 | Gambia, The 1,925,527 2014 45 | Guinea-Bissau 1,693,398 2014 46 | Gabon 1,672,597 2014 47 | Swaziland 1,419,623 2014 48 | Mauritius 1,331,155 2014 49 | Djibouti 810,179 2014 50 | Comoros 766,865 2014 51 | Equatorial Guinea 722,254 2014 52 | Western Sahara 554,795 2014 53 | Cape Verde 538,535 2014 54 | Sao Tome and Principe 190,428 2014 55 | Seychelles 91,650 2014 -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_02_code/car_crashes.csv: -------------------------------------------------------------------------------- 1 | Year,Car_Crash_Fatalities_US 1900,36 1901,54 1902,79 1903,117 1904,172 1905,252 1906,338 1907,581 1908,751 1909,1174 1910,1599 1911,2043 1912,2968 1913,4079 1914,4468 1915,6779 1916,7766 1917,9630 1918,10390 1919,10896 1920,12155 1921,13253 1922,14859 1923,17870 1924,18400 1925,20771 1926,22194 1927,24470 1928,26557 1929,29592 1930,31204 1931,31963 1932,27979 1933,29746 1934,34240 1935,34494 1936,36126 1937,37819 1938,31083 1939,30895 1940,32914 1941,38142 1942,27007 1943,22727 1944,23165 1945,26785 1946,31874 1947,31193 1948,30775 1949,30246 1950,33186 1951,35309 1952,36088 1953,36190 1954,33890 1955,36688 1956,37965 1957,36932 1958,35331 1959,36223 1960,36399 1961,36285 1962,38980 1963,41723 1964,45645 1965,47089 1966,50894 1967,50724 1968,52725 1969,53543 1970,52627 1971,52542 1972,54589 1973,54052 1974,45196 1975,44525 1976,45523 1977,47878 1978,50331 1979,51093 1980,51091 1981,49301 1982,43945 1983,42589 1984,44257 1985,43825 1986,46087 1987,46390 1988,47087 1989,45582 1990,44599 1991,41508 1992,39250 1993,40150 1994,40716 1995,41817 1996,42065 1997,42013 1998,41501 1999,41717 2000,41945 2001,42196 2002,43005 2003,42884 2004,42836 2005,43510 2006,42708 2007,41259 2008,37423 2009,33883 -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_02_code/oil.csv: -------------------------------------------------------------------------------- 1 | "Year","Oil prices in constant 1997 dollars. 1870-1997" 2 | "1870",58.53 3 | "1871",49.09 4 | "1872",24.68 5 | "1873",16.71 6 | "1874",19.86 7 | "1875",38.23 8 | "1876",36.11 9 | "1877",19.59 10 | "1878",14.91 11 | "1879",15.74 12 | "1880",15.40 13 | "1881",13.06 14 | "1882",19.07 15 | "1883",15.28 16 | "1884",15.82 17 | "1885",12.77 18 | "1886",12.05 19 | "1887",11.69 20 | "1888",13.85 21 | "1889",13.85 22 | "1890",10.07 23 | "1891",9.17 24 | "1892",10.79 25 | "1893",13.44 26 | "1894",21.17 27 | "1895",18.64 28 | "1896",13.21 29 | "1897",15.54 30 | "1898",21.94 31 | "1899",23.11 32 | "1900",18.64 33 | "1901",14.94 34 | "1902",16.90 35 | "1903",15.46 36 | "1904",11.15 37 | "1905",13.13 38 | "1906",12.48 39 | "1907",12.95 40 | "1908",12.59 41 | "1909",10.58 42 | "1910",10.58 43 | "1911",12.39 44 | "1912",15.53 45 | "1913",13.06 46 | "1914",10.22 47 | "1915",16.33 48 | "1916",19.72 49 | "1917",21.31 50 | "1918",18.84 51 | "1919",24.84 52 | "1920",15.67 53 | "1921",15.57 54 | "1922",12.73 55 | "1923",13.56 56 | "1924",15.54 57 | "1925",17.22 58 | "1926",12.14 59 | "1927",11.07 60 | "1928",12.02 61 | "1929",11.55 62 | "1930",6.92 63 | "1931",10.33 64 | "1932",8.38 65 | "1933",12.11 66 | "1934",11.46 67 | "1935",12.75 68 | "1936",13.32 69 | "1937",13.00 70 | "1938",11.90 71 | "1939",11.79 72 | "1940",12.55 73 | "1941",11.84 74 | "1942",11.25 75 | "1943",11.15 76 | "1944",10.99 77 | "1945",11.70 78 | "1946",14.01 79 | "1947",17.51 80 | "1948",17.27 81 | "1949",16.90 82 | "1950",15.79 83 | "1951",15.45 84 | "1952",16.24 85 | "1953",16.71 86 | "1954",16.77 87 | "1955",16.64 88 | "1956",17.80 89 | "1957",16.87 90 | "1958",16.13 91 | "1959",15.76 92 | "1960",15.66 93 | "1961",15.54 94 | "1962",15.30 95 | "1963",15.05 96 | "1964",14.69 97 | "1965",14.39 98 | "1966",14.18 99 | "1967",13.70 100 | "1968",13.66 101 | "1969",13.27 102 | "1970",13.56 103 | "1971",13.14 104 | "1972",14.19 105 | "1973",22.57 106 | "1974",23.09 107 | "1975",23.31 108 | "1976",22.91 109 | "1977",22.36 110 | "1978",43.06 111 | "1979",64.67 112 | "1980",64.68 113 | "1981",56.90 114 | "1982",48.79 115 | "1983",45.21 116 | "1984",41.40 117 | "1985",22.17 118 | "1986",25.52 119 | "1987",20.28 120 | "1988",22.87 121 | "1989",27.63 122 | "1990",22.95 123 | "1991",21.35 124 | "1992",18.38 125 | "1993",17.15 126 | "1994",18.27 127 | "1995",19.40 128 | "1996",20.52 129 | 130 | Oil prices in constant 1997 dollars. 1870-1997 131 | 132 | -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_03_code/B04881_chapter03_code/B04881_chapter03_code/B04881_chapter03_code02.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": null, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "## import dependencies\n", 12 | "from pyspark import SparkContext\n", 13 | "from pyspark.streaming import StreamingContext\n", 14 | "from pyspark.mllib.clustering import StreamingKMeans\n", 15 | "from pyspark.mllib.linalg import Vectors\n", 16 | "from pyspark.mllib.regression import LabeledPoint\n", 17 | "import uuid\n", 18 | "import os\n", 19 | "os.environ[\"PYSPARK_PYTHON\"] = \"python3\"" 20 | ] 21 | }, 22 | { 23 | "cell_type": "code", 24 | "execution_count": null, 25 | "metadata": { 26 | "collapsed": false 27 | }, 28 | "outputs": [], 29 | "source": [ 30 | "## spark Context and Streaming Spark Context\n", 31 | "job_uuid = 'job_'+ str(uuid.uuid4())\n", 32 | "\n", 33 | "sc = SparkContext( 'local', job_uuid)" 34 | ] 35 | }, 36 | { 37 | "cell_type": "code", 38 | "execution_count": null, 39 | "metadata": { 40 | "collapsed": false 41 | }, 42 | "outputs": [], 43 | "source": [ 44 | "sc.stop()" 45 | ] 46 | }, 47 | { 48 | "cell_type": "code", 49 | "execution_count": null, 50 | "metadata": { 51 | "collapsed": true 52 | }, 53 | "outputs": [], 54 | "source": [ 55 | "\n", 56 | "# streaming\n", 57 | "ssc = StreamingContext(sc,10)" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": null, 63 | "metadata": { 64 | "collapsed": true 65 | }, 66 | "outputs": [], 67 | "source": [ 68 | "ssc.stop()" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 5, 74 | "metadata": { 75 | "collapsed": true 76 | }, 77 | "outputs": [], 78 | "source": [ 79 | "# helper function to parse the data\n", 80 | "class Parser():\n", 81 | " def __init__(self,type='train',delimiter=',',num_elements=5, job_uuid=''):\n", 82 | " self.type=type\n", 83 | " self.delimiter=delimiter\n", 84 | " self.num_elements=num_elements\n", 85 | " self.job_uuid=job_uuid\n", 86 | " \n", 87 | " def parse(self,l):\n", 88 | " try:\n", 89 | " line = l.split(self.delimiter) \n", 90 | " if self.type=='test':\n", 91 | " category = float(line[0])\n", 92 | " feature_vector = Vectors.dense(line[1:])\n", 93 | " return LabeledPoint(category, feature_vector)\n", 94 | " elif self.type=='train':\n", 95 | " category = -1\n", 96 | " feature_vector = Vectors.dense(line)\n", 97 | " return LabeledPoint(category, feature_vector)\n", 98 | " else:\n", 99 | " # log exceptions\n", 100 | " f = open('/errors_events/{0}.txt'.format(self.job_uuid),'a')\n", 101 | " f.write('Unknown type: {0}'.format(self.type))\n", 102 | " f.close()\n", 103 | " except:\n", 104 | " # log errors\n", 105 | " f = open('/error_events/{0}.txt'.format(self.job_uuid),'a')\n", 106 | " f.write('Error parsing line: {0}'.format)\n", 107 | " f.close() \n" 108 | ] 109 | }, 110 | { 111 | "cell_type": "code", 112 | "execution_count": null, 113 | "metadata": { 114 | "collapsed": true 115 | }, 116 | "outputs": [], 117 | "source": [ 118 | "num_features = 2\n", 119 | "training_parser = Parser('train',',',num_features,job_uuid)\n", 120 | "\n", 121 | "\n", 122 | "trainingData = ssc.textFileStream(\"/training_data\").\\\n", 123 | " map(lambda x: training_parser.parse(x)).pprint()\n", 124 | "ssc.start()" 125 | ] 126 | }, 127 | { 128 | "cell_type": "code", 129 | "execution_count": 6, 130 | "metadata": { 131 | "collapsed": false 132 | }, 133 | "outputs": [ 134 | { 135 | "name": "stderr", 136 | "output_type": "stream", 137 | "text": [ 138 | "Traceback (most recent call last):\n", 139 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/util.py\", line 62, in call\n", 140 | " r = self.func(t, *rdds)\n", 141 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/dstream.py\", line 159, in \n", 142 | " func = lambda t, rdd: old_func(rdd)\n", 143 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 579, in update\n", 144 | " self._model.update(rdd, self._decayFactor, self._timeUnit)\n", 145 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 494, in update\n", 146 | " data, decayFactor, timeUnit)\n", 147 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 130, in callMLlibFunc\n", 148 | " return callJavaFunc(sc, api, *args)\n", 149 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in callJavaFunc\n", 150 | " args = [_py2java(sc, a) for a in args]\n", 151 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in \n", 152 | " args = [_py2java(sc, a) for a in args]\n", 153 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in _py2java\n", 154 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 155 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in \n", 156 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 157 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 88, in _py2java\n", 158 | " obj = sc._jvm.SerDe.loads(data)\n", 159 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/java_gateway.py\", line 538, in __call__\n", 160 | " self.target_id, self.name)\n", 161 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/protocol.py\", line 300, in get_return_value\n", 162 | " format(target_id, '.', name), value)\n", 163 | "py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.mllib.api.python.SerDe.loads.\n", 164 | ": net.razorvine.pickle.PickleException: expected zero arguments for construction of ClassDict (for numpy.dtype)\n", 165 | "\tat net.razorvine.pickle.objects.ClassDictConstructor.construct(ClassDictConstructor.java:23)\n", 166 | "\tat net.razorvine.pickle.Unpickler.load_reduce(Unpickler.java:701)\n", 167 | "\tat net.razorvine.pickle.Unpickler.dispatch(Unpickler.java:171)\n", 168 | "\tat net.razorvine.pickle.Unpickler.load(Unpickler.java:85)\n", 169 | "\tat net.razorvine.pickle.Unpickler.loads(Unpickler.java:98)\n", 170 | "\tat org.apache.spark.mllib.api.python.SerDe$.loads(PythonMLLibAPI.scala:1462)\n", 171 | "\tat org.apache.spark.mllib.api.python.SerDe.loads(PythonMLLibAPI.scala)\n", 172 | "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n", 173 | "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n", 174 | "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n", 175 | "\tat java.lang.reflect.Method.invoke(Method.java:497)\n", 176 | "\tat py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)\n", 177 | "\tat py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)\n", 178 | "\tat py4j.Gateway.invoke(Gateway.java:259)\n", 179 | "\tat py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)\n", 180 | "\tat py4j.commands.CallCommand.execute(CallCommand.java:79)\n", 181 | "\tat py4j.GatewayConnection.run(GatewayConnection.java:207)\n", 182 | "\tat java.lang.Thread.run(Thread.java:745)\n", 183 | "\n", 184 | "Traceback (most recent call last):\n", 185 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/util.py\", line 62, in call\n", 186 | " r = self.func(t, *rdds)\n", 187 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/dstream.py\", line 159, in \n", 188 | " func = lambda t, rdd: old_func(rdd)\n", 189 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 579, in update\n", 190 | " self._model.update(rdd, self._decayFactor, self._timeUnit)\n", 191 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 494, in update\n", 192 | " data, decayFactor, timeUnit)\n", 193 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 130, in callMLlibFunc\n", 194 | " return callJavaFunc(sc, api, *args)\n", 195 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in callJavaFunc\n", 196 | " args = [_py2java(sc, a) for a in args]\n", 197 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in \n", 198 | " args = [_py2java(sc, a) for a in args]\n", 199 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in _py2java\n", 200 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 201 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in \n", 202 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 203 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 88, in _py2java\n", 204 | " obj = sc._jvm.SerDe.loads(data)\n", 205 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/java_gateway.py\", line 538, in __call__\n", 206 | " self.target_id, self.name)\n", 207 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/protocol.py\", line 300, in get_return_value\n", 208 | " format(target_id, '.', name), value)\n", 209 | "py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.mllib.api.python.SerDe.loads.\n", 210 | ": net.razorvine.pickle.PickleException: expected zero arguments for construction of ClassDict (for numpy.dtype)\n", 211 | "\tat net.razorvine.pickle.objects.ClassDictConstructor.construct(ClassDictConstructor.java:23)\n", 212 | "\tat net.razorvine.pickle.Unpickler.load_reduce(Unpickler.java:701)\n", 213 | "\tat net.razorvine.pickle.Unpickler.dispatch(Unpickler.java:171)\n", 214 | "\tat net.razorvine.pickle.Unpickler.load(Unpickler.java:85)\n", 215 | "\tat net.razorvine.pickle.Unpickler.loads(Unpickler.java:98)\n", 216 | "\tat org.apache.spark.mllib.api.python.SerDe$.loads(PythonMLLibAPI.scala:1462)\n", 217 | "\tat org.apache.spark.mllib.api.python.SerDe.loads(PythonMLLibAPI.scala)\n", 218 | "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n", 219 | "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n", 220 | "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n", 221 | "\tat java.lang.reflect.Method.invoke(Method.java:497)\n", 222 | "\tat py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)\n", 223 | "\tat py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)\n", 224 | "\tat py4j.Gateway.invoke(Gateway.java:259)\n", 225 | "\tat py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)\n", 226 | "\tat py4j.commands.CallCommand.execute(CallCommand.java:79)\n", 227 | "\tat py4j.GatewayConnection.run(GatewayConnection.java:207)\n", 228 | "\tat java.lang.Thread.run(Thread.java:745)\n", 229 | "\n" 230 | ] 231 | }, 232 | { 233 | "name": "stdout", 234 | "output_type": "stream", 235 | "text": [ 236 | "-------------------------------------------\n", 237 | "Time: 2016-03-18 00:49:40\n", 238 | "-------------------------------------------\n", 239 | "\n", 240 | "-------------------------------------------\n", 241 | "Time: 2016-03-18 00:49:50\n", 242 | "-------------------------------------------\n", 243 | "\n" 244 | ] 245 | }, 246 | { 247 | "name": "stderr", 248 | "output_type": "stream", 249 | "text": [ 250 | "Traceback (most recent call last):\n", 251 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/util.py\", line 62, in call\n", 252 | " r = self.func(t, *rdds)\n", 253 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/dstream.py\", line 159, in \n", 254 | " func = lambda t, rdd: old_func(rdd)\n", 255 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 579, in update\n", 256 | " self._model.update(rdd, self._decayFactor, self._timeUnit)\n", 257 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 494, in update\n", 258 | " data, decayFactor, timeUnit)\n", 259 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 130, in callMLlibFunc\n", 260 | " return callJavaFunc(sc, api, *args)\n", 261 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in callJavaFunc\n", 262 | " args = [_py2java(sc, a) for a in args]\n", 263 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in \n", 264 | " args = [_py2java(sc, a) for a in args]\n", 265 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in _py2java\n", 266 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 267 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in \n", 268 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 269 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 88, in _py2java\n", 270 | " obj = sc._jvm.SerDe.loads(data)\n", 271 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/java_gateway.py\", line 538, in __call__\n", 272 | " self.target_id, self.name)\n", 273 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/protocol.py\", line 300, in get_return_value\n", 274 | " format(target_id, '.', name), value)\n", 275 | "py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.mllib.api.python.SerDe.loads.\n", 276 | ": net.razorvine.pickle.PickleException: expected zero arguments for construction of ClassDict (for numpy.dtype)\n", 277 | "\tat net.razorvine.pickle.objects.ClassDictConstructor.construct(ClassDictConstructor.java:23)\n", 278 | "\tat net.razorvine.pickle.Unpickler.load_reduce(Unpickler.java:701)\n", 279 | "\tat net.razorvine.pickle.Unpickler.dispatch(Unpickler.java:171)\n", 280 | "\tat net.razorvine.pickle.Unpickler.load(Unpickler.java:85)\n", 281 | "\tat net.razorvine.pickle.Unpickler.loads(Unpickler.java:98)\n", 282 | "\tat org.apache.spark.mllib.api.python.SerDe$.loads(PythonMLLibAPI.scala:1462)\n", 283 | "\tat org.apache.spark.mllib.api.python.SerDe.loads(PythonMLLibAPI.scala)\n", 284 | "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n", 285 | "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n", 286 | "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n", 287 | "\tat java.lang.reflect.Method.invoke(Method.java:497)\n", 288 | "\tat py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)\n", 289 | "\tat py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)\n", 290 | "\tat py4j.Gateway.invoke(Gateway.java:259)\n", 291 | "\tat py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)\n", 292 | "\tat py4j.commands.CallCommand.execute(CallCommand.java:79)\n", 293 | "\tat py4j.GatewayConnection.run(GatewayConnection.java:207)\n", 294 | "\tat java.lang.Thread.run(Thread.java:745)\n", 295 | "\n", 296 | "Traceback (most recent call last):\n", 297 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/util.py\", line 62, in call\n", 298 | " r = self.func(t, *rdds)\n", 299 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/dstream.py\", line 159, in \n", 300 | " func = lambda t, rdd: old_func(rdd)\n", 301 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 579, in update\n", 302 | " self._model.update(rdd, self._decayFactor, self._timeUnit)\n", 303 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 494, in update\n", 304 | " data, decayFactor, timeUnit)\n", 305 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 130, in callMLlibFunc\n", 306 | " return callJavaFunc(sc, api, *args)\n", 307 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in callJavaFunc\n", 308 | " args = [_py2java(sc, a) for a in args]\n", 309 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in \n", 310 | " args = [_py2java(sc, a) for a in args]\n", 311 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in _py2java\n", 312 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 313 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in \n", 314 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 315 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 88, in _py2java\n", 316 | " obj = sc._jvm.SerDe.loads(data)\n", 317 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/java_gateway.py\", line 538, in __call__\n", 318 | " self.target_id, self.name)\n", 319 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/protocol.py\", line 300, in get_return_value\n", 320 | " format(target_id, '.', name), value)\n", 321 | "py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.mllib.api.python.SerDe.loads.\n", 322 | ": net.razorvine.pickle.PickleException: expected zero arguments for construction of ClassDict (for numpy.dtype)\n", 323 | "\tat net.razorvine.pickle.objects.ClassDictConstructor.construct(ClassDictConstructor.java:23)\n", 324 | "\tat net.razorvine.pickle.Unpickler.load_reduce(Unpickler.java:701)\n", 325 | "\tat net.razorvine.pickle.Unpickler.dispatch(Unpickler.java:171)\n", 326 | "\tat net.razorvine.pickle.Unpickler.load(Unpickler.java:85)\n", 327 | "\tat net.razorvine.pickle.Unpickler.loads(Unpickler.java:98)\n", 328 | "\tat org.apache.spark.mllib.api.python.SerDe$.loads(PythonMLLibAPI.scala:1462)\n", 329 | "\tat org.apache.spark.mllib.api.python.SerDe.loads(PythonMLLibAPI.scala)\n", 330 | "\tat sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)\n", 331 | "\tat sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)\n", 332 | "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n", 333 | "\tat java.lang.reflect.Method.invoke(Method.java:497)\n", 334 | "\tat py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)\n", 335 | "\tat py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)\n", 336 | "\tat py4j.Gateway.invoke(Gateway.java:259)\n", 337 | "\tat py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)\n", 338 | "\tat py4j.commands.CallCommand.execute(CallCommand.java:79)\n", 339 | "\tat py4j.GatewayConnection.run(GatewayConnection.java:207)\n", 340 | "\tat java.lang.Thread.run(Thread.java:745)\n", 341 | "\n" 342 | ] 343 | }, 344 | { 345 | "name": "stdout", 346 | "output_type": "stream", 347 | "text": [ 348 | "-------------------------------------------\n", 349 | "Time: 2016-03-18 00:50:00\n", 350 | "-------------------------------------------\n", 351 | "\n", 352 | "-------------------------------------------\n", 353 | "Time: 2016-03-18 00:50:10\n", 354 | "-------------------------------------------\n", 355 | "(1.0, 1)\n", 356 | "(2.0, 1)\n", 357 | "(2.0, 1)\n", 358 | "(1.0, 1)\n", 359 | "(1.0, 1)\n", 360 | "(2.0, 1)\n", 361 | "(2.0, 1)\n", 362 | "(2.0, 1)\n", 363 | "(2.0, 1)\n", 364 | "(1.0, 1)\n", 365 | "...\n", 366 | "\n" 367 | ] 368 | }, 369 | { 370 | "name": "stderr", 371 | "output_type": "stream", 372 | "text": [ 373 | "Traceback (most recent call last):\n", 374 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/util.py\", line 62, in call\n", 375 | " r = self.func(t, *rdds)\n", 376 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/dstream.py\", line 159, in \n", 377 | " func = lambda t, rdd: old_func(rdd)\n", 378 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 579, in update\n", 379 | " self._model.update(rdd, self._decayFactor, self._timeUnit)\n", 380 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 494, in update\n", 381 | " data, decayFactor, timeUnit)\n", 382 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 130, in callMLlibFunc\n", 383 | " return callJavaFunc(sc, api, *args)\n", 384 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in callJavaFunc\n", 385 | " args = [_py2java(sc, a) for a in args]\n", 386 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in \n", 387 | " args = [_py2java(sc, a) for a in args]\n", 388 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in _py2java\n", 389 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 390 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in \n", 391 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 392 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 88, in _py2java\n", 393 | " obj = sc._jvm.SerDe.loads(data)\n", 394 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/java_gateway.py\", line 538, in __call__\n", 395 | " self.target_id, self.name)\n", 396 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/protocol.py\", line 300, in get_return_value\n", 397 | " format(target_id, '.', name), value)\n", 398 | "py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.mllib.api.python.SerDe.loads.\n", 399 | ": net.razorvine.pickle.PickleException: expected zero arguments for construction of ClassDict (for numpy.dtype)\n", 400 | "\tat net.razorvine.pickle.objects.ClassDictConstructor.construct(ClassDictConstructor.java:23)\n", 401 | "\tat net.razorvine.pickle.Unpickler.load_reduce(Unpickler.java:701)\n", 402 | "\tat net.razorvine.pickle.Unpickler.dispatch(Unpickler.java:171)\n", 403 | "\tat net.razorvine.pickle.Unpickler.load(Unpickler.java:85)\n", 404 | "\tat net.razorvine.pickle.Unpickler.loads(Unpickler.java:98)\n", 405 | "\tat org.apache.spark.mllib.api.python.SerDe$.loads(PythonMLLibAPI.scala:1462)\n", 406 | "\tat org.apache.spark.mllib.api.python.SerDe.loads(PythonMLLibAPI.scala)\n", 407 | "\tat sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)\n", 408 | "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n", 409 | "\tat java.lang.reflect.Method.invoke(Method.java:497)\n", 410 | "\tat py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)\n", 411 | "\tat py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)\n", 412 | "\tat py4j.Gateway.invoke(Gateway.java:259)\n", 413 | "\tat py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)\n", 414 | "\tat py4j.commands.CallCommand.execute(CallCommand.java:79)\n", 415 | "\tat py4j.GatewayConnection.run(GatewayConnection.java:207)\n", 416 | "\tat java.lang.Thread.run(Thread.java:745)\n", 417 | "\n", 418 | "Traceback (most recent call last):\n", 419 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/util.py\", line 62, in call\n", 420 | " r = self.func(t, *rdds)\n", 421 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/dstream.py\", line 159, in \n", 422 | " func = lambda t, rdd: old_func(rdd)\n", 423 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 579, in update\n", 424 | " self._model.update(rdd, self._decayFactor, self._timeUnit)\n", 425 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 494, in update\n", 426 | " data, decayFactor, timeUnit)\n", 427 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 130, in callMLlibFunc\n", 428 | " return callJavaFunc(sc, api, *args)\n", 429 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in callJavaFunc\n", 430 | " args = [_py2java(sc, a) for a in args]\n", 431 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in \n", 432 | " args = [_py2java(sc, a) for a in args]\n", 433 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in _py2java\n", 434 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 435 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in \n", 436 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 437 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 88, in _py2java\n", 438 | " obj = sc._jvm.SerDe.loads(data)\n", 439 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/java_gateway.py\", line 538, in __call__\n", 440 | " self.target_id, self.name)\n", 441 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/protocol.py\", line 300, in get_return_value\n", 442 | " format(target_id, '.', name), value)\n", 443 | "py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.mllib.api.python.SerDe.loads.\n", 444 | ": net.razorvine.pickle.PickleException: expected zero arguments for construction of ClassDict (for numpy.dtype)\n", 445 | "\tat net.razorvine.pickle.objects.ClassDictConstructor.construct(ClassDictConstructor.java:23)\n", 446 | "\tat net.razorvine.pickle.Unpickler.load_reduce(Unpickler.java:701)\n", 447 | "\tat net.razorvine.pickle.Unpickler.dispatch(Unpickler.java:171)\n", 448 | "\tat net.razorvine.pickle.Unpickler.load(Unpickler.java:85)\n", 449 | "\tat net.razorvine.pickle.Unpickler.loads(Unpickler.java:98)\n", 450 | "\tat org.apache.spark.mllib.api.python.SerDe$.loads(PythonMLLibAPI.scala:1462)\n", 451 | "\tat org.apache.spark.mllib.api.python.SerDe.loads(PythonMLLibAPI.scala)\n", 452 | "\tat sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)\n", 453 | "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n", 454 | "\tat java.lang.reflect.Method.invoke(Method.java:497)\n", 455 | "\tat py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)\n", 456 | "\tat py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)\n", 457 | "\tat py4j.Gateway.invoke(Gateway.java:259)\n", 458 | "\tat py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)\n", 459 | "\tat py4j.commands.CallCommand.execute(CallCommand.java:79)\n", 460 | "\tat py4j.GatewayConnection.run(GatewayConnection.java:207)\n", 461 | "\tat java.lang.Thread.run(Thread.java:745)\n", 462 | "\n" 463 | ] 464 | }, 465 | { 466 | "name": "stdout", 467 | "output_type": "stream", 468 | "text": [ 469 | "-------------------------------------------\n", 470 | "Time: 2016-03-18 00:50:20\n", 471 | "-------------------------------------------\n", 472 | "\n", 473 | "-------------------------------------------\n", 474 | "Time: 2016-03-18 00:50:30\n", 475 | "-------------------------------------------\n", 476 | "\n" 477 | ] 478 | }, 479 | { 480 | "name": "stderr", 481 | "output_type": "stream", 482 | "text": [ 483 | "Traceback (most recent call last):\n", 484 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/util.py\", line 62, in call\n", 485 | " r = self.func(t, *rdds)\n", 486 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/dstream.py\", line 159, in \n", 487 | " func = lambda t, rdd: old_func(rdd)\n", 488 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 579, in update\n", 489 | " self._model.update(rdd, self._decayFactor, self._timeUnit)\n", 490 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 494, in update\n", 491 | " data, decayFactor, timeUnit)\n", 492 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 130, in callMLlibFunc\n", 493 | " return callJavaFunc(sc, api, *args)\n", 494 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in callJavaFunc\n", 495 | " args = [_py2java(sc, a) for a in args]\n", 496 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in \n", 497 | " args = [_py2java(sc, a) for a in args]\n", 498 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in _py2java\n", 499 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 500 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in \n", 501 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 502 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 88, in _py2java\n", 503 | " obj = sc._jvm.SerDe.loads(data)\n", 504 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/java_gateway.py\", line 538, in __call__\n", 505 | " self.target_id, self.name)\n", 506 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/protocol.py\", line 300, in get_return_value\n", 507 | " format(target_id, '.', name), value)\n", 508 | "py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.mllib.api.python.SerDe.loads.\n", 509 | ": net.razorvine.pickle.PickleException: expected zero arguments for construction of ClassDict (for numpy.dtype)\n", 510 | "\tat net.razorvine.pickle.objects.ClassDictConstructor.construct(ClassDictConstructor.java:23)\n", 511 | "\tat net.razorvine.pickle.Unpickler.load_reduce(Unpickler.java:701)\n", 512 | "\tat net.razorvine.pickle.Unpickler.dispatch(Unpickler.java:171)\n", 513 | "\tat net.razorvine.pickle.Unpickler.load(Unpickler.java:85)\n", 514 | "\tat net.razorvine.pickle.Unpickler.loads(Unpickler.java:98)\n", 515 | "\tat org.apache.spark.mllib.api.python.SerDe$.loads(PythonMLLibAPI.scala:1462)\n", 516 | "\tat org.apache.spark.mllib.api.python.SerDe.loads(PythonMLLibAPI.scala)\n", 517 | "\tat sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)\n", 518 | "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n", 519 | "\tat java.lang.reflect.Method.invoke(Method.java:497)\n", 520 | "\tat py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)\n", 521 | "\tat py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)\n", 522 | "\tat py4j.Gateway.invoke(Gateway.java:259)\n", 523 | "\tat py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)\n", 524 | "\tat py4j.commands.CallCommand.execute(CallCommand.java:79)\n", 525 | "\tat py4j.GatewayConnection.run(GatewayConnection.java:207)\n", 526 | "\tat java.lang.Thread.run(Thread.java:745)\n", 527 | "\n", 528 | "Traceback (most recent call last):\n", 529 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/util.py\", line 62, in call\n", 530 | " r = self.func(t, *rdds)\n", 531 | " File \"/Applications/spark-1.5.0/python/pyspark/streaming/dstream.py\", line 159, in \n", 532 | " func = lambda t, rdd: old_func(rdd)\n", 533 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 579, in update\n", 534 | " self._model.update(rdd, self._decayFactor, self._timeUnit)\n", 535 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/clustering.py\", line 494, in update\n", 536 | " data, decayFactor, timeUnit)\n", 537 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 130, in callMLlibFunc\n", 538 | " return callJavaFunc(sc, api, *args)\n", 539 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in callJavaFunc\n", 540 | " args = [_py2java(sc, a) for a in args]\n", 541 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 122, in \n", 542 | " args = [_py2java(sc, a) for a in args]\n", 543 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in _py2java\n", 544 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 545 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 81, in \n", 546 | " obj = ListConverter().convert([_py2java(sc, x) for x in obj], sc._gateway._gateway_client)\n", 547 | " File \"/Applications/spark-1.5.0/python/pyspark/mllib/common.py\", line 88, in _py2java\n", 548 | " obj = sc._jvm.SerDe.loads(data)\n", 549 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/java_gateway.py\", line 538, in __call__\n", 550 | " self.target_id, self.name)\n", 551 | " File \"/Applications/spark-1.5.0/python/lib/py4j-0.8.2.1-src.zip/py4j/protocol.py\", line 300, in get_return_value\n", 552 | " format(target_id, '.', name), value)\n", 553 | "py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.mllib.api.python.SerDe.loads.\n", 554 | ": net.razorvine.pickle.PickleException: expected zero arguments for construction of ClassDict (for numpy.dtype)\n", 555 | "\tat net.razorvine.pickle.objects.ClassDictConstructor.construct(ClassDictConstructor.java:23)\n", 556 | "\tat net.razorvine.pickle.Unpickler.load_reduce(Unpickler.java:701)\n", 557 | "\tat net.razorvine.pickle.Unpickler.dispatch(Unpickler.java:171)\n", 558 | "\tat net.razorvine.pickle.Unpickler.load(Unpickler.java:85)\n", 559 | "\tat net.razorvine.pickle.Unpickler.loads(Unpickler.java:98)\n", 560 | "\tat org.apache.spark.mllib.api.python.SerDe$.loads(PythonMLLibAPI.scala:1462)\n", 561 | "\tat org.apache.spark.mllib.api.python.SerDe.loads(PythonMLLibAPI.scala)\n", 562 | "\tat sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)\n", 563 | "\tat sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)\n", 564 | "\tat java.lang.reflect.Method.invoke(Method.java:497)\n", 565 | "\tat py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:231)\n", 566 | "\tat py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:379)\n", 567 | "\tat py4j.Gateway.invoke(Gateway.java:259)\n", 568 | "\tat py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:133)\n", 569 | "\tat py4j.commands.CallCommand.execute(CallCommand.java:79)\n", 570 | "\tat py4j.GatewayConnection.run(GatewayConnection.java:207)\n", 571 | "\tat java.lang.Thread.run(Thread.java:745)\n", 572 | "\n" 573 | ] 574 | }, 575 | { 576 | "name": "stdout", 577 | "output_type": "stream", 578 | "text": [ 579 | "-------------------------------------------\n", 580 | "Time: 2016-03-18 00:50:40\n", 581 | "-------------------------------------------\n", 582 | "\n", 583 | "-------------------------------------------\n", 584 | "Time: 2016-03-18 00:50:50\n", 585 | "-------------------------------------------\n", 586 | "\n" 587 | ] 588 | } 589 | ], 590 | "source": [ 591 | "num_features = 2\n", 592 | "num_clusters = 3\n", 593 | "\n", 594 | "training_parser = Parser('train',',',num_features,job_uuid)\n", 595 | "test_parser = Parser('test',',',num_features+1,job_uuid)\n", 596 | "\n", 597 | "trainingData = ssc.textFileStream(\"/training_data\").\\\n", 598 | " map(lambda x: training_parser.parse(x)).map(lambda x: x.features).filter(lambda x: x is not None)\n", 599 | "testData = ssc.textFileStream(\"/test_data\").\\\n", 600 | " map(lambda x: test_parser.parse(x)).filter(lambda x: x is not None)\n", 601 | "streaming_clustering = StreamingKMeans(k=num_clusters, decayFactor=1.0).\\\n", 602 | " setRandomCenters(num_features,0,0)\n", 603 | "streaming_clustering.trainOn(trainingData)\n", 604 | "streaming_clustering.predictOnValues(testData.map(lambda x: (x.label, x.features))).\\\n", 605 | " pprint()\n", 606 | "ssc.start() " 607 | ] 608 | }, 609 | { 610 | "cell_type": "code", 611 | "execution_count": null, 612 | "metadata": { 613 | "collapsed": false 614 | }, 615 | "outputs": [], 616 | "source": [ 617 | "ssc.stop()" 618 | ] 619 | }, 620 | { 621 | "cell_type": "code", 622 | "execution_count": null, 623 | "metadata": { 624 | "collapsed": false 625 | }, 626 | "outputs": [], 627 | "source": [ 628 | "streaming_clustering.latestModel().clusterCenters" 629 | ] 630 | }, 631 | { 632 | "cell_type": "code", 633 | "execution_count": null, 634 | "metadata": { 635 | "collapsed": true 636 | }, 637 | "outputs": [], 638 | "source": [ 639 | "import random\n", 640 | "labels = []\n", 641 | "for i in range(1,100):\n", 642 | " class_num=random.randint(1,3)\n", 643 | " labels.append(class_num)" 644 | ] 645 | }, 646 | { 647 | "cell_type": "code", 648 | "execution_count": null, 649 | "metadata": { 650 | "collapsed": true 651 | }, 652 | "outputs": [], 653 | "source": [ 654 | "import numpy as np\n", 655 | "\n", 656 | "dists = {}\n", 657 | "dists[1] = lambda : [np.random.normal(1,1),np.random.normal(1,2)]\n", 658 | "dists[2] = lambda : [np.random.normal(3,1),np.random.normal(7,2)]\n", 659 | "dists[3] = lambda : [np.random.normal(7,1),np.random.normal(-10,1)]\n", 660 | "\n", 661 | "f=open('sample_train.txt','w')\n", 662 | "for i in labels:\n", 663 | " f.write(\",\".join([str(n) for n in dists[i]()])+'\\n')\n", 664 | "f.close()\n", 665 | "\n", 666 | "f=open('sample_test.txt','w')\n", 667 | "for i in labels:\n", 668 | " f.write(\",\".join([str(i)]+[str(n) for n in dists[i]()])+'\\n')\n", 669 | "f.close()" 670 | ] 671 | }, 672 | { 673 | "cell_type": "code", 674 | "execution_count": null, 675 | "metadata": { 676 | "collapsed": false 677 | }, 678 | "outputs": [], 679 | "source": [ 680 | "streaming_clustering.latestModel().centers" 681 | ] 682 | }, 683 | { 684 | "cell_type": "code", 685 | "execution_count": null, 686 | "metadata": { 687 | "collapsed": false 688 | }, 689 | "outputs": [], 690 | "source": [] 691 | } 692 | ], 693 | "metadata": { 694 | "kernelspec": { 695 | "display_name": "Python 3", 696 | "language": "python", 697 | "name": "python3" 698 | }, 699 | "language_info": { 700 | "codemirror_mode": { 701 | "name": "ipython", 702 | "version": 3 703 | }, 704 | "file_extension": ".py", 705 | "mimetype": "text/x-python", 706 | "name": "python", 707 | "nbconvert_exporter": "python", 708 | "pygments_lexer": "ipython3", 709 | "version": "3.5.1" 710 | } 711 | }, 712 | "nbformat": 4, 713 | "nbformat_minor": 0 714 | } 715 | -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_03_code/B04881_chapter03_code/B04881_chapter03_code/kmeans.txt: -------------------------------------------------------------------------------- 1 | label x_coord y_coord 2 | 0 10.3115072306 14.268936828 3 | 1 8.62864753558 10.5301395463 4 | 2 10.1329927191 12.6865915205 5 | 3 8.53299938552 20.931670407 6 | 4 9.75155339821 15.6860787817 7 | 5 8.40765054866 14.9132008157 8 | 6 9.69092390662 18.8414725142 9 | 7 8.74703484648 21.583856037 10 | 8 10.5688501241 11.9692704376 11 | 9 8.35341784127 16.3724161468 12 | 10 8.78784169965 12.0106635033 13 | 11 8.59850999283 17.7866174735 14 | 12 9.79265872853 17.8060269887 15 | 13 9.76106507666 15.2101486051 16 | 14 10.5901278608 16.8742698897 17 | 15 10.3826428684 12.9601663833 18 | 16 8.36319940153 12.1659917155 19 | 17 10.0762093013 18.7722090213 20 | 18 9.87873461318 21.1059573903 21 | 19 9.62257975246 21.9145960554 22 | 20 10.5044500988 14.9447936699 23 | 21 10.2867050706 14.7596766828 24 | 22 9.94223546241 14.2302883091 25 | 23 9.89114599604 18.9087198326 26 | 24 9.54925627338 19.9879840442 27 | 25 10.6876804628 20.6213891302 28 | 26 9.86875454217 21.9442839864 29 | 27 9.54675005237 14.5170825201 30 | 28 10.1226720605 16.1196626801 31 | 29 10.280674128 14.1401453398 32 | 30 10.4679480787 17.6169718282 33 | 31 9.70859268986 19.1758648367 34 | 32 8.94443413621 16.412697249 35 | 33 8.765414239 14.3151305716 36 | 34 8.52151355578 13.4351771087 37 | 35 10.1240942859 15.3976873119 38 | 36 9.64735062766 16.0654351069 39 | 37 10.0198375939 17.7372397172 40 | 38 9.14732737741 21.4627957224 41 | 39 9.55881349865 14.1505410109 42 | 40 10.3993281871 13.9962698989 43 | 41 10.1000660529 16.1960844053 44 | 42 9.3809880512 12.4934091953 45 | 43 10.3264047149 20.8515280503 46 | 44 9.08921838346 12.227589757 47 | 45 9.51874974337 18.5076227919 48 | 46 9.37047344926 17.0847056243 49 | 47 9.50526209443 16.2501583236 50 | 48 8.29381069206 15.097289748 51 | 49 10.3513234441 12.3740034506 52 | 50 10.1743142845 12.8648701744 53 | 51 8.95660556112 10.7371023089 54 | 52 8.53533572106 15.4059973301 55 | 53 9.47405574611 17.3575910345 56 | 54 9.46052960694 13.4462585846 57 | 55 8.50288026203 18.7818297386 58 | 56 10.4555701409 13.9435803913 59 | 57 8.28864956999 19.7366046133 60 | 58 8.60401937281 15.9169558068 61 | 59 8.74572823007 19.3599783822 62 | 60 9.30403994679 16.0834045916 63 | 61 8.80215418901 16.413730623 64 | 62 9.11541203826 18.5747363782 65 | 63 8.93280628795 10.8507611453 66 | 64 9.98141493999 12.4006367643 67 | 65 9.24837758469 13.3747691635 68 | 66 9.57625640286 17.2741047365 69 | 67 8.36834404146 19.238861828 70 | 68 10.331680295 19.4904038976 71 | 69 9.47402832821 11.9789798876 72 | 70 8.72434048255 11.6781112639 73 | 71 8.37847797222 13.5110965867 74 | 72 10.3696323066 19.1034063178 75 | 73 9.23570674976 20.1289110877 76 | 74 10.6810097562 11.0927716743 77 | 75 9.91985728934 15.7197577423 78 | 76 9.96230726369 12.2587658304 79 | 77 9.35756214104 21.3105698834 80 | 78 10.1423486245 11.3708393545 81 | 79 9.18728626825 21.293710774 82 | 80 8.69585509965 17.4973288736 83 | 81 8.63504564821 17.0186995625 84 | 82 8.47483834343 12.4830507541 85 | 83 9.97381300604 11.0320466477 86 | 84 9.29021826589 11.51745067 87 | 85 8.2593357761 15.3554405066 88 | 86 9.70983168219 13.8847476768 89 | 87 8.7305173338 14.3352253514 90 | 88 10.2845441801 16.750360401 91 | 89 9.56238782392 14.8742651551 92 | 90 9.92451580874 21.808703773 93 | 91 9.0847995416 19.2792418283 94 | 92 10.2317714832 12.9499210495 95 | 93 8.31254480964 18.9081103967 96 | 94 10.3862341127 15.8267158499 97 | 95 8.28916438742 14.8832259143 98 | 96 10.602139806 17.2415794469 99 | 97 10.3527868539 19.0486134168 100 | 98 10.6659117905 13.1459552806 101 | 99 10.4293033243 13.351523296 102 | 100 -8.6280564252 5.03529771165 103 | 101 -8.69830857554 4.77987951803 104 | 102 -8.51387220856 5.17495275394 105 | 103 -8.69494048279 5.09227180478 106 | 104 -8.55827277874 4.75489799647 107 | 105 -8.73352159594 4.96237821581 108 | 106 -8.61990775397 5.16583562131 109 | 107 -8.60021945302 5.16902142588 110 | 108 -8.58415182501 4.87895940714 111 | 109 -8.5895823374 5.12826424504 112 | 110 -8.46851847083 4.94501164043 113 | 111 -8.57302269143 4.71472256546 114 | 112 -8.46698386699 4.65102111847 115 | 113 -8.68007777727 5.17272711933 116 | 114 -8.4566456586 5.14150590636 117 | 115 -8.67724916133 4.66596822288 118 | 116 -8.60536740173 5.14827529605 119 | 117 -8.62032023989 4.92784681567 120 | 118 -8.48986960846 5.02281906084 121 | 119 -8.45218763998 4.73383345428 122 | 120 -8.45483821557 4.96928060905 123 | 121 -8.68509108858 5.185493147 124 | 122 -8.62599381185 4.64402715563 125 | 123 -8.48983202997 4.64970348588 126 | 124 -8.56623893599 4.86162767202 127 | 125 -8.68157616823 4.85686094193 128 | 126 -8.48937867138 4.66821542303 129 | 127 -8.44242999822 5.1205499783 130 | 128 -8.55738588216 4.64584663301 131 | 129 -8.62903026072 4.76508005991 132 | 130 -8.45667253531 5.05817554126 133 | 131 -8.65158865378 4.73928574847 134 | 132 -8.65019503927 4.97639452344 135 | 133 -8.55393309692 5.22736658258 136 | 134 -8.68771159404 4.67470714082 137 | 135 -8.55913972415 4.64893026691 138 | 136 -8.47378271316 5.06976119806 139 | 137 -8.56061090877 4.76290278798 140 | 138 -8.63979760907 5.21277428662 141 | 139 -8.72848658056 4.72557322812 142 | 140 -8.52956794936 4.94630032833 143 | 141 -8.73102006051 5.09470388427 144 | 142 -8.55007577526 4.82979638619 145 | 143 -8.60925647852 4.96487808944 146 | 144 -8.59610289959 4.94058858598 147 | 145 -8.66611739036 5.04274083693 148 | 146 -8.66502044707 4.98484834465 149 | 147 -8.71904560619 4.89169009923 150 | 148 -8.73343992204 4.62472106053 151 | 149 -8.6253200774 5.01527082555 152 | 150 -8.62403003405 4.76942194817 153 | 151 -8.5651666715 4.64372209548 154 | 152 -8.68033386621 4.72552093804 155 | 153 -8.64995061495 4.66265424198 156 | 154 -8.6729505348 4.91105128629 157 | 155 -8.63490542566 4.75109077007 158 | 156 -8.73694404785 5.07787127466 159 | 157 -8.46322495502 4.77017488227 160 | 158 -8.67210356147 5.02250102305 161 | 159 -8.55577871946 5.01714842494 162 | 160 -8.64282441438 4.62453370048 163 | 161 -8.5279429624 5.05563282495 164 | 162 -8.74138848465 4.76765529864 165 | 163 -8.5354540964 4.949837357 166 | 164 -8.7009045304 4.79392503476 167 | 165 -8.57997216587 4.62281750571 168 | 166 -8.61649163708 5.14617410808 169 | 167 -8.64712474244 5.06922349397 170 | 168 -8.68796612728 5.22372245892 171 | 169 -8.47066971046 5.13500372048 172 | 170 -8.63512822101 5.11928940633 173 | 171 -8.73913909118 4.66044316998 174 | 172 -8.49315105995 4.83508940722 175 | 173 -8.5485444619 4.64002694178 176 | 174 -8.72335818491 4.94948916402 177 | 175 -8.71237564936 5.18943773376 178 | 176 -8.72298647146 4.69680992496 179 | 177 -8.66423892556 4.97396357019 180 | 178 -8.49780679676 4.88237823833 181 | 179 -8.60465343391 5.08507508595 182 | 180 -8.46592006286 4.84656140556 183 | 181 -8.67733131948 4.79923805543 184 | 182 -8.53464234718 5.20624202646 185 | 183 -8.7407126075 4.78777968881 186 | 184 -8.73731670783 4.73995199043 187 | 185 -8.48115788849 5.00857469566 188 | 186 -8.48899803298 4.86833077857 189 | 187 -8.7132963177 4.70120926362 190 | 188 -8.46276050784 4.60507510974 191 | 189 -8.50266115379 4.84188866954 192 | 190 -8.7024037483 4.93912885094 193 | 191 -8.45615517554 5.12499539401 194 | 192 -8.63034248491 4.65311597013 195 | 193 -8.6073354155 4.96474855246 196 | 194 -8.69495710706 4.78181684816 197 | 195 -8.49456247753 5.12773370514 198 | 196 -8.50561875811 4.78318064494 199 | 197 -8.48709219794 5.13078905392 200 | 198 -8.72154076244 4.90421601677 201 | 199 -8.49539856035 5.12993379571 202 | 200 11.8572543074 12.9824050674 203 | 201 12.5590020611 13.5362409771 204 | 202 12.3708540156 14.3765506793 205 | 203 13.0657923163 14.37586479 206 | 204 13.4050609482 13.5361040702 207 | 205 14.3881649224 13.2425838404 208 | 206 13.4184278782 13.3948122631 209 | 207 13.1337479641 13.4013833846 210 | 208 12.6911473396 14.0498744618 211 | 209 13.8020647742 13.5516826463 212 | 210 12.1749423487 14.0789796826 213 | 211 13.4693633806 13.1931931375 214 | 212 12.8774431494 13.8919956236 215 | 213 12.4454650386 13.659287009 216 | 214 14.4506518337 13.9655980122 217 | 215 13.5197449925 14.1005257914 218 | 216 12.232382511 13.2941456358 219 | 217 13.2474701587 14.2223729424 220 | 218 14.4384846071 13.0147113446 221 | 219 14.3926768548 14.2001372536 222 | 220 12.8976974949 13.9887859501 223 | 221 12.4798412702 13.9592549679 224 | 222 11.894861907 14.2245606662 225 | 223 12.3080134206 13.0713582365 226 | 224 13.5291671897 14.0977147368 227 | 225 11.8624818387 13.577225552 228 | 226 14.0649634859 14.0440702609 229 | 227 12.1517466682 13.5335491473 230 | 228 13.4468557645 13.3408935261 231 | 229 12.677456394 14.1483968679 232 | 230 12.1927329427 13.2124475038 233 | 231 12.5784759778 13.2537256592 234 | 232 14.2628965688 14.0280259637 235 | 233 13.250844055 13.4163491982 236 | 234 12.893595828 13.7175709914 237 | 235 12.1581376154 13.5077747239 238 | 236 13.4529197632 14.066437182 239 | 237 13.5569245277 14.0031340334 240 | 238 13.4323295502 13.3346120797 241 | 239 12.7900774772 13.0057385899 242 | 240 13.1116450692 13.4912749702 243 | 241 14.4555601108 13.0498826175 244 | 242 13.2594620809 14.0409443615 245 | 243 11.9752556494 13.0180916852 246 | 244 11.9095032196 13.9203899022 247 | 245 13.6589191699 13.6081151145 248 | 246 12.8169477017 13.5255924702 249 | 247 13.3440096685 13.2014192104 250 | 248 13.3304453801 13.9578200496 251 | 249 13.7882008545 14.0007261475 252 | 250 12.129983269 13.3652236336 253 | 251 13.5520628986 13.9447533567 254 | 252 12.7509982737 13.9254553847 255 | 253 13.630149136 13.1214287332 256 | 254 13.2298058257 13.6238765673 257 | 255 12.8580006055 13.2454367822 258 | 256 13.5945381252 13.3393589822 259 | 257 11.9096030575 13.8860152369 260 | 258 11.8480338385 13.0100554405 261 | 259 13.6542039977 13.9898311279 262 | 260 13.906469295 13.0246791914 263 | 261 14.4881102111 14.0264684457 264 | 262 13.6426117935 13.512067787 265 | 263 12.1211455806 13.7436713705 266 | 264 12.5833530864 13.8419706231 267 | 265 12.6994978802 14.2013501601 268 | 266 14.1713294399 13.2033632999 269 | 267 13.33021111 13.966330412 270 | 268 13.7901787628 14.0169135061 271 | 269 12.522573556 14.0198121111 272 | 270 13.3774192423 13.8041721509 273 | 271 11.8819772504 13.6766027866 274 | 272 14.5039158255 14.2118507943 275 | 273 13.8961413375 13.8814760249 276 | 274 13.1307350425 13.4350748671 277 | 275 14.1080997253 14.1652745827 278 | 276 14.4290186451 13.1910246099 279 | 277 13.911687949 12.9051110061 280 | 278 12.4338934354 14.2641967302 281 | 279 11.8774796495 14.1184693129 282 | 280 12.5637030912 13.7635657887 283 | 281 13.6961491033 13.5334758198 284 | 282 12.4664470124 14.3612433246 285 | 283 14.5009021275 13.091723144 286 | 284 13.9505875735 13.3717894214 287 | 285 13.7288587354 13.3867407456 288 | 286 12.8218554763 13.6393215078 289 | 287 12.9207770617 13.2640142663 290 | 288 12.0533986346 14.2084997747 291 | 289 13.2214662253 13.7374705972 292 | 290 14.478387134 13.1811448588 293 | 291 12.8982446085 13.7217395461 294 | 292 13.6811378185 14.2374335486 295 | 293 12.5807641932 14.3524550287 296 | 294 12.7884466003 13.4012488597 297 | 295 12.2520661241 14.341458844 298 | 296 13.5617756872 14.2012255746 299 | 297 13.1373214991 14.0101186351 300 | 298 14.1831449692 13.0184985804 301 | 299 12.9367099922 14.3460907361 302 | 300 -0.409733617662 20.4932027362 303 | 301 -0.53025202909 21.2336153711 304 | 302 0.805298865014 21.2920990435 305 | 303 0.269061799177 21.5247364623 306 | 304 0.557704651711 21.4739798639 307 | 305 -0.465574585364 21.2270388109 308 | 306 -0.594409856521 20.0984490883 309 | 307 -0.587378701289 20.3881006112 310 | 308 0.13466589325 21.5034923873 311 | 309 0.0954136301745 20.6118400702 312 | 310 -0.0507424122069 20.0940069044 313 | 311 -0.431371596856 20.7357348465 314 | 312 -0.191751883351 20.3987605518 315 | 313 -0.23743806806 21.0549267792 316 | 314 0.189789356366 21.3425379318 317 | 315 -0.608405413552 21.4964242513 318 | 316 0.0132438173255 20.9812617308 319 | 317 1.03611644904 20.1108609211 320 | 318 0.157303894309 20.6590058467 321 | 319 0.127652301365 20.089134664 322 | 320 0.838759766361 20.0909552558 323 | 321 -0.366981364134 20.5254102321 324 | 322 1.31255710828 20.4866797664 325 | 323 0.91408487929 20.7245380474 326 | 324 0.70597531423 21.4424392492 327 | 325 0.801987938153 20.8007811347 328 | 326 1.0814667445 20.1814916685 329 | 327 0.716677627964 21.4178436886 330 | 328 -0.287190112382 21.2869454766 331 | 329 0.356239858297 21.0814383573 332 | 330 -0.465089874097 20.9373238063 333 | 331 -0.439621447801 20.6013640532 334 | 332 0.933857705757 21.3517523697 335 | 333 0.743139451601 21.009894433 336 | 334 1.2078102808 21.2085832199 337 | 335 1.18904766681 21.4578351825 338 | 336 -0.636341489406 20.5202874421 339 | 337 -0.410235331441 21.0059480159 340 | 338 0.69420044454 21.0439104304 341 | 339 1.24497068278 20.9867861942 342 | 340 0.431927470595 20.5106358918 343 | 341 0.157415442655 20.3442626938 344 | 342 -0.411850844858 20.605653559 345 | 343 -0.862226404576 20.4336318611 346 | 344 1.24025008652 20.4448548281 347 | 345 -0.447944076863 20.2201969194 348 | 346 0.116240475208 20.7593095106 349 | 347 -0.0547056073419 20.0118687244 350 | 348 0.392055547052 21.0982831101 351 | 349 -0.617768527323 21.376100696 352 | 350 0.685420325426 20.7048225944 353 | 351 -0.381264504767 21.2705378953 354 | 352 1.38085082201 20.0446647575 355 | 353 0.310531324101 20.5044170682 356 | 354 -0.832659295482 21.1284803617 357 | 355 1.16990802786 21.45257706 358 | 356 -0.816387418621 21.0797274848 359 | 357 -0.117790360925 20.822151327 360 | 358 0.282533177652 21.512056033 361 | 359 0.477304299939 20.2319532685 362 | 360 -0.730298155799 20.5980981155 363 | 361 0.826817535047 21.4420768411 364 | 362 1.39703672147 20.1192378201 365 | 363 1.45349405804 20.6569659545 366 | 364 1.12023440414 21.416505867 367 | 365 -0.82089139015 20.8945966455 368 | 366 -0.490836377746 20.4684080243 369 | 367 0.683205344737 20.1080521814 370 | 368 1.36604571921 21.4726066774 371 | 369 0.284810962555 21.296816303 372 | 370 0.848395006616 20.0558028078 373 | 371 -0.231135473046 20.0927011774 374 | 372 1.35954763842 20.7976572266 375 | 373 0.267182118073 21.3445676477 376 | 374 -0.502492497882 21.0134522497 377 | 375 0.484252896513 20.2033800987 378 | 376 -0.472900495668 21.3325137297 379 | 377 -0.87838903558 20.4330063272 380 | 378 0.186799006901 20.1974817046 381 | 379 0.475846090086 20.9704365702 382 | 380 -0.578767777439 20.5551591964 383 | 381 1.04217659043 20.2348700285 384 | 382 -0.882898379844 20.5440307535 385 | 383 0.240898202673 21.0382001067 386 | 384 -0.456960540473 20.1190881515 387 | 385 0.325605933553 20.509758109 388 | 386 -0.217460473738 20.1188870841 389 | 387 0.417981728289 21.3199858642 390 | 388 1.09051868719 20.5103046733 391 | 389 0.228393461858 20.4324287899 392 | 390 -0.768024702606 20.1557271847 393 | 391 0.66443275319 21.2138546535 394 | 392 0.338575983451 20.0458345276 395 | 393 -0.433336388866 20.2017888324 396 | 394 0.695035564616 20.8641253991 397 | 395 -0.764888104204 20.4642804389 398 | 396 -0.237837463433 20.6002896117 399 | 397 0.143039876397 21.1229267255 400 | 398 1.18448314495 21.1527509958 401 | 399 0.578914872866 20.3235956978 402 | 400 -16.7125954886 8.81675239076 403 | 401 -16.3081485339 8.96016241133 404 | 402 -14.7147599358 8.83404910137 405 | 403 -15.2266826785 10.1728761635 406 | 404 -16.5092100842 10.2190657495 407 | 405 -17.3514368704 10.0710677309 408 | 406 -15.8470727977 10.5418601015 409 | 407 -17.0656456808 9.26681727841 410 | 408 -14.6261860275 9.98841444369 411 | 409 -17.3214892425 9.72860895149 412 | 410 -16.8402629499 10.1272900369 413 | 411 -15.9952614053 9.46224135839 414 | 412 -14.8481669148 9.86196090298 415 | 413 -14.562628902 9.53640561253 416 | 414 -14.5742945814 10.6881399838 417 | 415 -16.0451691332 9.32445466784 418 | 416 -16.3416368494 8.99692947061 419 | 417 -16.7496420037 9.42088704649 420 | 418 -17.4343584771 9.29566149711 421 | 419 -16.0373817766 10.7174737724 422 | 420 -14.5608488057 10.1623364719 423 | 421 -14.6298464668 10.7582791349 424 | 422 -17.3828063458 9.79750574452 425 | 423 -14.6087164696 9.00518627861 426 | 424 -17.0307388196 8.90037254687 427 | 425 -14.7842145996 9.9928217489 428 | 426 -14.8693990451 10.0554016453 429 | 427 -17.2344786182 9.75511308123 430 | 428 -17.0696596432 10.1408073293 431 | 429 -15.6293131024 10.3525345729 432 | 430 -14.5966525646 10.5539221377 433 | 431 -17.2010329896 9.25505090791 434 | 432 -15.6065232487 9.67043436722 435 | 433 -15.2118970045 10.337924124 436 | 434 -16.8667712116 10.6305419941 437 | 435 -17.2970946326 8.79368427255 438 | 436 -14.7029712263 9.3968909377 439 | 437 -15.5712542182 9.95336100489 440 | 438 -15.9534539422 10.1194640636 441 | 439 -14.9666405647 9.24861925558 442 | 440 -16.4898229843 10.5370914995 443 | 441 -16.7489226826 9.0600262119 444 | 442 -15.6861010802 9.89408876641 445 | 443 -14.6389001636 9.74714772298 446 | 444 -16.3171889211 8.90280525858 447 | 445 -14.2452043284 9.26925147368 448 | 446 -17.0204694838 9.55165969576 449 | 447 -16.5140417875 8.90138593388 450 | 448 -16.4981833398 10.5567884728 451 | 449 -17.3709408667 10.4547905864 452 | 450 -15.4935957948 9.78884599569 453 | 451 -17.2476234767 9.55793145777 454 | 452 -15.6856367937 10.5456030892 455 | 453 -15.4135224003 9.72166691809 456 | 454 -17.314198494 10.4495094753 457 | 455 -16.153340855 10.0429908553 458 | 456 -16.4887392891 9.67771115636 459 | 457 -17.4120140757 9.35681674927 460 | 458 -14.3774785184 9.47163622619 461 | 459 -16.2433101426 9.91360464619 462 | 460 -16.8029619276 8.92837463875 463 | 461 -14.6599821087 9.45919973113 464 | 462 -15.4986150976 10.0585744001 465 | 463 -15.2315328485 9.97889188674 466 | 464 -15.1898969442 9.58599568484 467 | 465 -16.166056752 9.68594932782 468 | 466 -17.3407602032 8.83222071828 469 | 467 -14.9070769891 10.5506355159 470 | 468 -16.9988133166 10.1681641208 471 | 469 -14.2865464737 10.3980042576 472 | 470 -16.2815220916 10.1561256698 473 | 471 -17.017199005 9.54674912273 474 | 472 -16.4606700876 9.40517312549 475 | 473 -14.5502890262 9.61555025055 476 | 474 -14.8735157201 9.04848574336 477 | 475 -16.5410449965 10.7459545117 478 | 476 -15.7058621274 9.47686021283 479 | 477 -16.6376948213 10.3707480589 480 | 478 -14.7735742322 9.64801290535 481 | 479 -14.6917698635 10.1300457502 482 | 480 -16.2116521353 10.1617687166 483 | 481 -15.1009842283 10.1716684802 484 | 482 -15.0348080398 9.41229075739 485 | 483 -17.4398644412 9.46879896978 486 | 484 -15.3557221551 10.488642791 487 | 485 -15.7266833875 8.99785069207 488 | 486 -17.0916280445 10.1067963318 489 | 487 -16.4977217763 9.43324203543 490 | 488 -15.930662395 8.92222251103 491 | 489 -15.7737072585 9.57278573977 492 | 490 -14.8111521831 9.00572790166 493 | 491 -16.4764990495 9.55816733233 494 | 492 -17.2668254248 10.6394850605 495 | 493 -15.7088533071 10.0848594109 496 | 494 -15.2188088243 10.1470519227 497 | 495 -15.7601786927 10.1925632626 498 | 496 -15.9577126031 9.56120819164 499 | 497 -17.3530000247 10.7103829108 500 | 498 -17.2785147394 10.4620996345 501 | 499 -14.8665619511 8.8276897818 502 | 500 19.508504192 6.85190878937 503 | 501 15.6272802504 6.44690782451 504 | 502 21.9742077811 5.67312604847 505 | 503 16.421112162 5.5079351745 506 | 504 17.5462775447 6.33280345931 507 | 505 16.2410277879 6.04157960592 508 | 506 13.7868316885 6.10670912009 509 | 507 22.2067912649 6.05516393032 510 | 508 17.3992258339 5.48934429758 511 | 509 16.4489444989 5.44000483251 512 | 510 21.326072146 6.43180531698 513 | 511 20.6239792118 5.81448774826 514 | 512 22.5646093288 5.40504150446 515 | 513 15.2996005185 6.44536421157 516 | 514 19.7192427969 5.15679871509 517 | 515 17.7141406458 5.79753740973 518 | 516 17.0710946281 6.19441635301 519 | 517 16.5554464417 5.40100442988 520 | 518 18.6053592515 6.91642061692 521 | 519 16.2579597533 6.7415808529 522 | 520 21.2241671731 6.13200324251 523 | 521 20.6808453822 5.48908115074 524 | 522 15.2885121877 6.14408272753 525 | 523 21.9861584691 5.18539334938 526 | 524 20.3302450417 6.04771359295 527 | 525 22.5583989715 5.99637938358 528 | 526 15.2888732861 6.79296841047 529 | 527 16.0353914413 5.26976539041 530 | 528 14.2013103001 5.69459747847 531 | 529 16.8502467138 6.59407022819 532 | 530 20.233582989 6.6662196918 533 | 531 17.8354542645 6.32620051353 534 | 532 17.6677784774 6.35750869805 535 | 533 18.7765388403 5.28784823863 536 | 534 14.5418200457 5.52771829138 537 | 535 20.3906761221 5.70199013455 538 | 536 19.9094752125 6.33798981938 539 | 537 15.6794054611 6.27229103576 540 | 538 13.9120643795 6.03968698523 541 | 539 20.5781934896 6.07767696794 542 | 540 22.4869008559 6.60695121878 543 | 541 17.9915130874 5.37007456026 544 | 542 21.0448870788 6.28890309048 545 | 543 17.1429606705 6.20014808336 546 | 544 17.3351463911 6.19307025379 547 | 545 14.077928559 6.42106807557 548 | 546 13.791609955 6.68685890397 549 | 547 15.2545869316 5.55491581819 550 | 548 22.1655764747 5.33960312719 551 | 549 15.8912739207 5.24553741056 552 | 550 15.8655767494 5.62636121508 553 | 551 20.6043239053 5.37671407489 554 | 552 14.2805565595 6.09731699256 555 | 553 17.4525146933 6.3613724117 556 | 554 20.3055455231 5.28229487637 557 | 555 19.9179687239 5.77982597712 558 | 556 20.2993994659 6.60740027989 559 | 557 22.3033358096 5.33413965851 560 | 558 15.7780471863 6.0541858112 561 | 559 14.1556968683 6.83702162615 562 | 560 17.8786656011 6.41449219509 563 | 561 21.3818939027 6.5184127265 564 | 562 17.3883392377 6.08316027548 565 | 563 18.9347980059 6.46799455218 566 | 564 22.385401254 6.17680765401 567 | 565 19.8779070813 5.2089261995 568 | 566 13.8842092354 6.56581218289 569 | 567 21.8046503139 5.41053994329 570 | 568 18.9372229707 6.02953175054 571 | 569 16.5301120585 6.30997041524 572 | 570 17.8336625022 6.50020929693 573 | 571 17.4935504172 5.9431268959 574 | 572 21.2964805745 6.06740263815 575 | 573 18.59710038 6.87800794767 576 | 574 20.0113703207 6.52984036552 577 | 575 21.5462948474 5.89056061397 578 | 576 16.2110863547 6.73856768007 579 | 577 13.8391677296 5.7096685183 580 | 578 16.0177475256 5.24924039397 581 | 579 15.7045683357 5.61862105962 582 | 580 17.5860237485 6.56352228598 583 | 581 20.2979903613 6.07882195588 584 | 582 19.3398239698 6.19016276822 585 | 583 16.1260188659 6.52384301058 586 | 584 21.9030159625 5.52773592539 587 | 585 22.2604724186 5.68441840259 588 | 586 16.6141270157 6.65032655561 589 | 587 21.2533192018 5.85218960562 590 | 588 20.6051808422 5.76968301711 591 | 589 22.5709309159 5.73753999417 592 | 590 22.2617093361 6.79705368664 593 | 591 20.6261588202 5.26507748679 594 | 592 16.8019026973 6.91363548208 595 | 593 14.0350815085 6.23591314749 596 | 594 20.7168899213 5.3917463701 597 | 595 20.7617194217 6.4757090294 598 | 596 17.5846242548 6.23281006743 599 | 597 18.1919574503 6.31649277372 600 | 598 19.5881090517 5.40374365861 601 | 599 18.714166383 6.20430444673 602 | 600 30.8027709733 0.492773745248 603 | 601 30.4388783244 0.495941543213 604 | 602 30.6689821623 0.514254855886 605 | 603 30.8657427137 0.507826522308 606 | 604 30.7799950168 0.504833935898 607 | 605 30.5119462144 0.39549473413 608 | 606 30.7936345908 0.502666121854 609 | 607 30.3021623649 0.385387480531 610 | 608 30.7963269754 0.543261046307 611 | 609 30.3223904773 0.505931994466 612 | 610 30.8332982209 0.4050109536 613 | 611 30.5913305419 0.50483255671 614 | 612 30.8556750807 0.532927797797 615 | 613 30.5162258021 0.464826586015 616 | 614 30.4016232333 0.530944471689 617 | 615 30.8637505942 0.420178458661 618 | 616 30.3882068075 0.505638021428 619 | 617 30.4897170974 0.399214865431 620 | 618 30.5810740718 0.431929087732 621 | 619 30.2729587712 0.49892581469 622 | 620 30.6239887908 0.437301678997 623 | 621 30.6115557853 0.530180384104 624 | 622 30.809550174 0.379351791956 625 | 623 30.8636861444 0.431408526529 626 | 624 30.4871954077 0.484151486712 627 | 625 30.3701387763 0.51660255307 628 | 626 30.4561096398 0.43344236683 629 | 627 30.3017771362 0.466725532174 630 | 628 30.4007600263 0.540119510128 631 | 629 30.2178856438 0.505131256291 632 | 630 30.4746551861 0.464629546093 633 | 631 30.8416259669 0.398489059493 634 | 632 30.2176004999 0.426926211157 635 | 633 30.2557945349 0.531689358605 636 | 634 30.5072240692 0.373742956559 637 | 635 30.7184055591 0.519906091621 638 | 636 30.6522094575 0.472516713312 639 | 637 30.7237013274 0.518175439272 640 | 638 30.5274338709 0.51539113635 641 | 639 30.5556191259 0.490498434087 642 | 640 30.7064653988 0.455763297449 643 | 641 30.259909125 0.458612591012 644 | 642 30.3884226028 0.504005291906 645 | 643 30.5915941424 0.501425118737 646 | 644 30.4172534872 0.442821993172 647 | 645 30.514631645 0.439289485805 648 | 646 30.4610814895 0.48248688923 649 | 647 30.2802955784 0.537412001109 650 | 648 30.3906107633 0.455792798666 651 | 649 30.5650911556 0.427454461723 652 | 650 30.6830660277 0.526263738357 653 | 651 30.6148705021 0.482405457983 654 | 652 30.3668090327 0.481049801621 655 | 653 30.7403021613 0.457786375529 656 | 654 30.5309154859 0.44032861937 657 | 655 30.4561473124 0.515806266579 658 | 656 30.287454654 0.442853565634 659 | 657 30.6938139391 0.510532967552 660 | 658 30.6252136393 0.39229460982 661 | 659 30.5288410942 0.424026438307 662 | 660 30.7092980524 0.444662830598 663 | 661 30.2941842097 0.483952796716 664 | 662 30.5449407751 0.460720238807 665 | 663 30.4192903338 0.470406361879 666 | 664 30.6419918569 0.450713071646 667 | 665 30.7301542676 0.372982285166 668 | 666 30.4655874786 0.525662607775 669 | 667 30.3820335723 0.509309221764 670 | 668 30.5769367891 0.458276520678 671 | 669 30.7247723726 0.481125080563 672 | 670 30.7553483186 0.43778474891 673 | 671 30.3521070482 0.493937833612 674 | 672 30.3587315678 0.439181670991 675 | 673 30.2549417986 0.489043237693 676 | 674 30.3608020417 0.386230722248 677 | 675 30.3584854089 0.519489561558 678 | 676 30.8425626891 0.512372899033 679 | 677 30.6593827302 0.518035854352 680 | 678 30.3550070438 0.475515006294 681 | 679 30.5077843596 0.41952865046 682 | 680 30.3929734769 0.404124040078 683 | 681 30.383560212 0.542582342554 684 | 682 30.3838171369 0.48843414335 685 | 683 30.4426095321 0.478426919826 686 | 684 30.3387708354 0.480000061541 687 | 685 30.4191883865 0.542479300134 688 | 686 30.7900919838 0.526915590957 689 | 687 30.2602011252 0.517648288057 690 | 688 30.7402991022 0.529713049121 691 | 689 30.3566196282 0.493947017859 692 | 690 30.298206624 0.427615263452 693 | 691 30.2411376916 0.512639621953 694 | 692 30.4480508155 0.389731005273 695 | 693 30.2198425161 0.391801551089 696 | 694 30.3015886508 0.51504672209 697 | 695 30.2501430588 0.483429204969 698 | 696 30.3447834597 0.436554583172 699 | 697 30.7617678776 0.431644846452 700 | 698 30.4385849002 0.518446604492 701 | 699 30.2559029505 0.4152485049 702 | 700 11.158784231 7.29183591529 703 | 701 11.6668399344 9.56371400272 704 | 702 11.0611028074 6.28772697413 705 | 703 11.4062765336 5.33144308921 706 | 704 11.6585667494 3.72248481302 707 | 705 11.1183726058 4.90401753847 708 | 706 11.4428108421 4.02272607864 709 | 707 11.3040927686 9.71576213441 710 | 708 10.8324535287 4.31637593742 711 | 709 11.7869924311 6.47933592894 712 | 710 11.2905094557 6.40254214868 713 | 711 11.2066700014 3.98881294954 714 | 712 11.507717325 4.96544910651 715 | 713 10.8209787879 9.45587512665 716 | 714 11.8867998574 9.50216591836 717 | 715 10.8295290418 7.2089160138 718 | 716 10.8533738438 8.98482722519 719 | 717 11.6103218681 5.82275240211 720 | 718 11.4576125083 2.8747957941 721 | 719 11.976811356 3.95136424427 722 | 720 11.0672569696 3.47448687261 723 | 721 11.9790665233 4.1386643667 724 | 722 11.0172501639 5.31406047992 725 | 723 11.6691467753 6.25563295966 726 | 724 11.559087271 8.75298315785 727 | 725 10.9090219875 7.76846740772 728 | 726 11.023047746 5.20777834175 729 | 727 11.4452151987 4.81722398981 730 | 728 11.0567356784 3.6916878886 731 | 729 11.5398060595 5.60678698937 732 | 730 11.3096246373 4.61583071393 733 | 731 11.4839034284 5.42466954615 734 | 732 11.5213277997 7.10237988476 735 | 733 11.2704044132 5.96452610503 736 | 734 11.0181992941 6.59362665313 737 | 735 11.0575456838 4.34382537752 738 | 736 11.3517911168 8.96512175571 739 | 737 11.9316419196 3.62533421905 740 | 738 11.4934682406 9.14632563801 741 | 739 11.5957164561 9.25073650161 742 | 740 11.3295786891 6.64495742793 743 | 741 11.6747010464 7.19276949238 744 | 742 11.8564240762 8.74028962141 745 | 743 10.9468868961 2.45651152546 746 | 744 10.7241903517 4.46512466762 747 | 745 11.2833166539 4.68941156903 748 | 746 11.8927619799 3.07577638336 749 | 747 10.8839278884 5.49131430831 750 | 748 11.6880333445 5.94745010815 751 | 749 11.1825734498 8.00372491917 752 | 750 11.0542513117 5.50753041672 753 | 751 11.4386484533 2.61517142469 754 | 752 11.1274827617 8.6870214069 755 | 753 11.3483869953 9.06771633528 756 | 754 11.610384799 7.33796336114 757 | 755 11.915836597 5.48125244412 758 | 756 11.8245337311 7.77991685855 759 | 757 11.0351463449 6.43429730055 760 | 758 11.4397047015 2.92778423774 761 | 759 10.9718592645 7.69677710758 762 | 760 11.8220233517 5.97530678831 763 | 761 11.8720766406 7.90602129426 764 | 762 11.189445475 4.46682246057 765 | 763 11.7931318099 3.92558735742 766 | 764 11.5016133561 2.68686533465 767 | 765 10.8319863148 5.42413825513 768 | 766 11.0569410565 6.19623653133 769 | 767 11.5164488989 2.9945667649 770 | 768 11.928608071 7.37404916583 771 | 769 10.9584623281 5.01644676131 772 | 770 11.355860991 8.54299664603 773 | 771 11.7479179967 6.91939177836 774 | 772 11.8022476128 4.05451440957 775 | 773 11.400456738 7.87381713026 776 | 774 10.8266415024 2.7889896989 777 | 775 11.4712456427 4.90325259898 778 | 776 11.3199557696 4.06745594572 779 | 777 11.4214827362 3.11435880588 780 | 778 11.6091344374 8.72262780011 781 | 779 11.218224125 5.50602035264 782 | 780 11.3775127676 8.569141546 783 | 781 10.9193235914 4.37980738382 784 | 782 11.3211809253 4.77908493039 785 | 783 11.10277631 8.03607221119 786 | 784 10.8304880661 7.51766807523 787 | 785 11.0342236057 7.11926106605 788 | 786 11.4382267269 8.55719281471 789 | 787 11.4685975625 4.23647817366 790 | 788 11.5890217062 7.76908153504 791 | 789 11.726168639 6.31197264361 792 | 790 11.313553394 9.26651337377 793 | 791 11.9493607513 4.09039976702 794 | 792 11.0218618901 6.68605600806 795 | 793 11.1986913756 3.83736697234 796 | 794 11.6686447316 7.98798657397 797 | 795 11.8270156821 5.7907320059 798 | 796 11.1966169205 4.61704992768 799 | 797 11.7013509632 4.50705297893 800 | 798 11.9309243453 2.80682407708 801 | 799 11.7964335377 9.69784508177 802 | 800 5.49590585841 6.21378174769 803 | 801 4.6220719042 0.11136794558 804 | 802 5.41700371112 0.0115519818437 805 | 803 4.36534165997 4.31292284938 806 | 804 6.28271104028 0.970773127217 807 | 805 4.92713405101 2.91627531518 808 | 806 5.22147288742 4.16134850336 809 | 807 4.92275003139 -0.101833088016 810 | 808 4.43457360773 -0.305906297773 811 | 809 5.1832005847 1.22244765487 812 | 810 4.5223988718 6.20891999036 813 | 811 6.07955793869 6.14021546908 814 | 812 4.75803338612 1.27060893783 815 | 813 6.13028771455 1.48053062061 816 | 814 5.34247511187 4.27501447665 817 | 815 5.01645859404 0.78995425301 818 | 816 5.69159930787 2.02603453803 819 | 817 6.02350986775 1.22436268421 820 | 818 4.74721012076 5.06215793384 821 | 819 4.41380013887 4.61622300156 822 | 820 5.6638273332 0.375103162777 823 | 821 6.25562215604 1.96059183667 824 | 822 5.81904569038 4.28293203864 825 | 823 4.68285315761 6.73071781971 826 | 824 4.54391410352 4.92354673222 827 | 825 4.2879356088 2.34252399475 828 | 826 5.01722092098 0.878948613569 829 | 827 5.59749056822 6.60650753909 830 | 828 5.9501304399 3.51260431734 831 | 829 5.96383779659 0.508839071368 832 | 830 5.69193635267 5.86544225229 833 | 831 4.64943223976 -0.673544855162 834 | 832 5.51944977175 2.74033279 835 | 833 4.97660785471 5.97045216576 836 | 834 5.21695205128 3.5718044128 837 | 835 5.50535321589 1.58984284844 838 | 836 5.43912593254 1.88175774526 839 | 837 5.9231577062 6.68740278678 840 | 838 5.84241558645 5.06055557098 841 | 839 5.62192907603 0.0938177993541 842 | 840 5.83686867325 0.238386606315 843 | 841 6.03332459371 5.67578872026 844 | 842 5.54611179647 4.33936527004 845 | 843 4.73924377476 5.75255004745 846 | 844 6.03182411052 0.702895266098 847 | 845 5.62129681611 0.525349734935 848 | 846 5.2103862938 0.0581603087322 849 | 847 4.75447961719 0.974905952186 850 | 848 4.30534776955 3.72443240991 851 | 849 5.36884841766 3.55845115635 852 | 850 5.08809808628 1.85858494634 853 | 851 5.17666248925 1.81934975364 854 | 852 4.92995153331 2.86232760419 855 | 853 5.9837848786 1.67043730655 856 | 854 4.68406507188 2.09838193325 857 | 855 6.27545844675 -0.500578764932 858 | 856 5.30980956569 3.9538498219 859 | 857 5.66601962881 -0.285534970809 860 | 858 4.82997885259 4.74978654625 861 | 859 4.65618751198 -0.0603457839816 862 | 860 4.63604807577 3.71268039696 863 | 861 4.49467373283 4.70355581499 864 | 862 4.33771271875 0.710850911463 865 | 863 6.12310720515 3.92856265639 866 | 864 5.544282952 -0.293324207112 867 | 865 5.48407987084 0.98688600389 868 | 866 5.67194103676 2.63906141794 869 | 867 5.83953716852 1.95091312655 870 | 868 5.676232794 4.91964767066 871 | 869 4.274179067 2.97853571423 872 | 870 5.95778348023 3.1577523611 873 | 871 4.41512847956 4.52070508243 874 | 872 5.76258206134 0.579526401171 875 | 873 4.47705445272 5.49587156778 876 | 874 5.3236073495 0.243139371301 877 | 875 5.07722016611 5.73824370882 878 | 876 4.65741086652 5.28057741061 879 | 877 5.22168207162 5.16999616405 880 | 878 5.42737356839 0.829525912509 881 | 879 6.10347897197 4.35544445263 882 | 880 5.83987557867 4.16180067246 883 | 881 6.16097499663 2.30387154018 884 | 882 5.39449483703 2.37324969144 885 | 883 6.21057873484 1.67145192295 886 | 884 4.6654483665 4.77435653551 887 | 885 6.23490234854 5.97608789243 888 | 886 4.49650632961 -0.21401439511 889 | 887 6.10395039752 4.15813116963 890 | 888 5.88357137872 2.09415797874 891 | 889 5.78271827943 0.0981430684213 892 | 890 4.78445256142 5.35476552684 893 | 891 4.5328995516 5.75236150857 894 | 892 4.41871574635 5.27209400721 895 | 893 5.81704348291 1.14011286148 896 | 894 6.14798660059 3.36935448611 897 | 895 4.78213873255 3.13836756678 898 | 896 6.09334610708 1.36651605538 899 | 897 4.95436535529 3.51359382171 900 | 898 5.73182993656 0.532370700298 901 | 899 4.78063405337 1.63276326433 902 | 900 8.44627728914 6.20428416404 903 | 901 10.0908830569 6.80068259424 904 | 902 8.92042420228 6.66634462673 905 | 903 9.2602401068 6.74085647912 906 | 904 13.1388066189 5.95246841601 907 | 905 12.0665655891 6.344353486 908 | 906 9.54347680452 6.59436340907 909 | 907 12.5042616239 6.33878198863 910 | 908 13.7792051376 5.98564377689 911 | 909 10.5781153631 6.72298893564 912 | 910 10.1584918407 6.96173786276 913 | 911 11.0023467623 5.9790187981 914 | 912 14.2873861885 6.4903927406 915 | 913 8.60982586296 6.36631799683 916 | 914 9.15279319875 6.05517878797 917 | 915 13.1587262566 6.8911789943 918 | 916 9.04769419533 6.80217357796 919 | 917 10.9754725002 6.60341913593 920 | 918 11.1117673093 6.65352787261 921 | 919 9.28754767909 6.48486494199 922 | 920 9.94593814432 6.08325309823 923 | 921 11.8903841587 7.05581294502 924 | 922 12.4926201674 6.7272027382 925 | 923 12.8904171623 6.98831104724 926 | 924 9.81221014197 6.07499781321 927 | 925 14.2385157599 6.86295437841 928 | 926 12.6463069754 7.06153641526 929 | 927 12.6145111699 6.72231747195 930 | 928 13.307808458 6.9040021134 931 | 929 13.0372987869 6.15525460933 932 | 930 10.1015066056 6.2974364313 933 | 931 9.48200120856 6.34393359466 934 | 932 9.20790604526 6.15485100978 935 | 933 9.91151468643 6.10702680625 936 | 934 8.31672519651 6.76320726223 937 | 935 13.2819347774 5.99956913553 938 | 936 12.3856441208 6.60045238066 939 | 937 12.4891251832 6.42036119898 940 | 938 9.73961622935 6.15734899442 941 | 939 12.5216074653 6.81229198714 942 | 940 13.0123511951 7.00529778938 943 | 941 12.3377871877 7.04271901046 944 | 942 8.25533460685 6.41186241908 945 | 943 11.9860283256 6.4472723172 946 | 944 12.3008733939 7.01804559513 947 | 945 9.93463204334 6.88057541232 948 | 946 11.6326037723 6.46541008207 949 | 947 10.708779727 6.71658433099 950 | 948 10.3013552059 6.68083723953 951 | 949 9.64404553786 6.31499200979 952 | 950 11.7372645168 6.21689440557 953 | 951 9.07913054295 6.71068423335 954 | 952 8.73888537597 6.86511573234 955 | 953 13.2098955919 6.05501239286 956 | 954 10.1862351793 6.79105304692 957 | 955 12.0422926134 6.24932851771 958 | 956 13.0488020788 6.04014933955 959 | 957 13.981278178 6.02835140255 960 | 958 12.7545171796 6.90182305453 961 | 959 9.4584728994 6.32284295896 962 | 960 12.2227696188 6.7836414067 963 | 961 12.8766399989 6.73408560372 964 | 962 8.68038220746 6.40690143483 965 | 963 11.0719968846 5.9768202123 966 | 964 9.04893011197 6.83990567174 967 | 965 11.8759188615 6.63837310498 968 | 966 13.7578306176 6.33468667074 969 | 967 11.8303181248 6.6846245456 970 | 968 10.4745385836 6.32356743345 971 | 969 9.23347693098 6.8508606655 972 | 970 11.3599612371 7.048137721 973 | 971 10.7789563325 6.69891829385 974 | 972 11.4062004097 6.39461548919 975 | 973 9.57865214882 6.07009008745 976 | 974 10.0771072904 6.05088459382 977 | 975 11.1588568899 6.69175681273 978 | 976 12.4652131933 6.22397893303 979 | 977 11.231169231 6.91827233301 980 | 978 11.0938739615 6.5176043077 981 | 979 14.0369433144 6.78155517648 982 | 980 12.5355741793 6.62300688025 983 | 981 11.255388451 6.67333444226 984 | 982 12.3198665936 6.52876886341 985 | 983 10.6914247876 7.05375750589 986 | 984 9.38506432778 6.80623310203 987 | 985 13.3131031343 6.79058923212 988 | 986 12.8055765066 6.86631924418 989 | 987 14.011437617 6.48463505876 990 | 988 10.7112210458 6.31811970322 991 | 989 8.23761201248 6.55868657035 992 | 990 11.8909641196 6.03041275714 993 | 991 8.56757691745 6.27612742985 994 | 992 11.1157480379 7.02810517989 995 | 993 14.2476117877 6.82992805158 996 | 994 9.96087387591 6.26521770812 997 | 995 9.33880538002 6.48275888526 998 | 996 11.2615153211 7.0413843863 999 | 997 13.2276106439 6.86583454485 1000 | 998 14.3492664376 5.96297719149 1001 | -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_03_code/B04881_chapter03_code/B04881_chapter03_code/kmeans2.txt: -------------------------------------------------------------------------------- 1 | label x_coord y_coord 2 | 0 21.1725293405 -13.6819076724 3 | 1 -10.3243331445 -23.837153528 4 | 2 16.2602399565 -18.9948260971 5 | 3 -24.9831170567 -4.21611417607 6 | 4 -1.44848822979 -25.3932652506 7 | 5 11.1600164687 -23.3227255765 8 | 6 -22.3589271223 -12.9943299939 9 | 7 24.7591686276 -6.77496593612 10 | 8 -16.2901547561 19.9705938426 11 | 9 23.4156795802 8.76677856375 12 | 10 -4.26858261116 -25.3650488144 13 | 11 15.4055285146 20.2030653613 14 | 12 -20.9952703793 -13.6574628044 15 | 13 -16.8812603311 -19.7178318309 16 | 14 -22.6367979923 10.8420107099 17 | 15 -22.1207650276 -12.0262506808 18 | 16 13.7220646612 -21.8886247198 19 | 17 -17.4744029762 -18.0094779643 20 | 18 25.7017928173 3.35165775346 21 | 19 21.8347953953 -13.442541578 22 | 20 14.9546593028 20.5815539154 23 | 21 -5.64471055399 -25.1303198989 24 | 22 18.371995904 17.3911285129 25 | 23 -17.0823508459 18.2957340124 26 | 24 22.1774561167 -11.6339133835 27 | 25 -20.7584938042 13.9365468354 28 | 26 -24.6862505369 7.02230933226 29 | 27 1.9559608272 -25.5447228961 30 | 28 16.9939629145 -18.5720735796 31 | 29 -4.80305690017 24.9863402678 32 | 30 -22.4129604386 12.5529211842 33 | 31 21.069059008 -14.0844986865 34 | 32 -25.0292167513 -0.309188827413 35 | 33 12.5469430002 21.7302338077 36 | 34 -25.6276612042 2.46751657952 37 | 35 -7.3284307166 -24.8629812384 38 | 36 -5.83217056409 -24.825936731 39 | 37 -23.2919594465 10.0720069027 40 | 38 -25.6878234904 0.862263359891 41 | 39 -16.7086049985 19.0469957522 42 | 40 -16.0097243103 19.7325336857 43 | 41 21.7873130106 -12.6240408867 44 | 42 9.04972114573 -23.6420474572 45 | 43 16.109307432 20.0427802921 46 | 44 -21.7477861845 13.1355241165 47 | 45 -5.8929036074 24.844306175 48 | 46 11.9153676099 22.3897152172 49 | 47 3.81746868144 -24.7803370118 50 | 48 20.658413773 15.5033139868 51 | 49 12.2637032782 22.6290123957 52 | 50 -10.6545299601 -23.0495192963 53 | 51 1.40078334398 -25.68645256 54 | 52 22.6926230049 -12.5785965078 55 | 53 -24.3366574951 8.78504504813 56 | 54 -20.431758067 14.8533990596 57 | 55 24.1806725919 -7.11237951322 58 | 56 -24.3510051149 -6.49603681602 59 | 57 -22.1244820152 -13.4009320599 60 | 58 7.05440302605 -24.4361792731 61 | 59 24.4607268407 -8.21060173301 62 | 60 10.2049328927 -23.8097640365 63 | 61 -25.4524742055 -1.37021966758 64 | 62 23.8302697323 -7.73381874373 65 | 63 21.6957692708 -13.1161162265 66 | 64 23.3915881031 10.0580064514 67 | 65 -22.6268402159 11.6840551238 68 | 66 25.364000199 4.71948361301 69 | 67 9.43800469058 23.6630254622 70 | 68 12.2479267108 -22.2297546783 71 | 69 -21.0252932222 13.9880111606 72 | 70 -10.3121635341 22.9160049543 73 | 71 -25.6354733317 0.763390130502 74 | 72 24.5620889081 6.39520178291 75 | 73 -25.3476151599 -0.580586947775 76 | 74 -17.1592288483 18.5969718043 77 | 75 19.5335225535 -16.1340378805 78 | 76 16.0177615721 -19.7004269166 79 | 77 -17.1629856265 18.9314032499 80 | 78 24.5351410238 6.90975866304 81 | 79 2.70210376628 25.5618293317 82 | 80 3.36198821401 -25.6106101471 83 | 81 9.44441960891 24.1405026199 84 | 82 -22.7315540603 11.2395604181 85 | 83 19.1523112014 -16.0747985177 86 | 84 -25.5011433288 -0.519839729668 87 | 85 -14.4295834421 -21.3704103011 88 | 86 1.81363769387 -25.4942520228 89 | 87 -24.0659469092 -8.87576431392 90 | 88 12.3148556301 21.9718626096 91 | 89 23.6915931173 -9.04001505671 92 | 90 14.4845247735 20.948847634 93 | 91 -5.17340953313 25.2982213922 94 | 92 5.85306057144 -24.6155685731 95 | 93 -25.6399319411 -2.13767491982 96 | 94 -12.4552829366 -21.7055362647 97 | 95 -14.3163956887 -20.8627509961 98 | 96 25.3874718007 2.64456089685 99 | 97 -25.8158865064 2.13247358142 100 | 98 8.72219050734 23.612913077 101 | 99 20.846916044 15.4752244625 102 | 100 12.8807073204 -22.3731422455 103 | 101 22.4442432544 13.0281609686 104 | 102 -4.92327114082 24.5959641235 105 | 103 -15.7507293168 -20.3591178786 106 | 104 19.4096823656 16.2906375326 107 | 105 19.7053119003 -16.8649219326 108 | 106 25.5339559777 0.0438221439197 109 | 107 14.4328692275 -21.5834885705 110 | 108 -4.33245056502 24.88971475 111 | 109 -10.2820214927 23.0683551517 112 | 110 -25.1113860195 2.58909263405 113 | 111 19.7932628042 -15.6363387454 114 | 112 -25.1039698258 -3.04121586268 115 | 113 -14.0058069778 -21.2945664644 116 | 114 -15.5206737124 19.5999521461 117 | 115 -24.2069815852 -9.24484824695 118 | 116 -15.093761357 -20.4967927968 119 | 117 13.0169203756 -21.658867941 120 | 118 -24.0237761386 7.14572215837 121 | 119 -18.0333976622 -18.680662189 122 | 120 19.0874020772 -17.4746641969 123 | 121 24.6713424591 5.06530705051 124 | 122 -24.9765751293 1.21508420724 125 | 123 -15.5926916996 -20.6291980011 126 | 124 -0.311746884384 25.3535349492 127 | 125 -21.1363244099 15.0523141041 128 | 126 -2.85290601926 25.704489247 129 | 127 -19.4092415944 -16.243225014 130 | 128 -16.0440632173 -19.5313494484 131 | 129 -22.0072658342 13.7655882686 132 | 130 25.3286783976 -1.19630527597 133 | 131 23.8309686114 8.08042301523 134 | 132 22.3382952288 -11.5897614669 135 | 133 -15.0566127142 -21.1607096111 136 | 134 25.4637152763 -0.882505017556 137 | 135 9.06957008911 -23.5720510332 138 | 136 16.7786010084 18.5953222304 139 | 137 -25.2490793768 5.54397596992 140 | 138 4.41247941478 -25.4605428483 141 | 139 -20.5139326793 15.3274393905 142 | 140 22.472791018 -11.0286182826 143 | 141 -18.0404588437 18.5838459243 144 | 142 24.3413348688 6.60780652632 145 | 143 15.1345688245 20.2761326878 146 | 144 25.2756066677 0.893112386561 147 | 145 -16.1815999765 -19.5513067987 148 | 146 23.2785497387 10.8548924577 149 | 147 11.719296432 -22.4671465602 150 | 148 13.6422688669 21.600159208 151 | 149 25.837580927 2.02634254093 152 | 150 -14.7474621362 20.431701856 153 | 151 -25.7128753215 -3.58203110722 154 | 152 -18.1068551493 -18.1207271514 155 | 153 7.20698764834 -24.8793343837 156 | 154 22.7181162323 10.5153648906 157 | 155 2.31690998283 24.9984464994 158 | 156 6.84019533826 24.1276198013 159 | 157 -20.6016699337 -15.7728539092 160 | 158 -20.7794862773 -14.371645451 161 | 159 16.1767949438 -19.5487358975 162 | 160 -19.5823873273 -16.6431370615 163 | 161 -2.52598563269 -25.7820298347 164 | 162 13.9992910016 -21.3100395061 165 | 163 -13.9837667475 -21.3939548609 166 | 164 -22.1274525527 13.5758755967 167 | 165 21.9030255828 13.7120465829 168 | 166 -25.0775743 3.87796599111 169 | 167 23.6195576565 10.4190708504 170 | 168 -25.3024276888 2.88013227991 171 | 169 -18.6436961648 17.1287150674 172 | 170 -24.3604481169 7.04636475475 173 | 171 -17.0522516877 18.986155555 174 | 172 -25.0703828431 0.695287125955 175 | 173 4.64995928791 25.5806161989 176 | 174 11.8195241768 -23.0756705339 177 | 175 12.6227220852 21.845195978 178 | 176 -6.99862545922 24.0445500703 179 | 177 -11.0886961298 -23.2565995913 180 | 178 19.9356371128 -15.6128270678 181 | 179 -3.11967634152 -25.3729733707 182 | 180 -9.95324692891 23.2332401699 183 | 181 23.348934911 -9.6889330463 184 | 182 8.10166434172 -24.6461371776 185 | 183 -5.6930254742 -25.3155869068 186 | 184 19.5019512725 16.0342701251 187 | 185 14.571220228 -20.3219671952 188 | 186 25.11701854 -5.63481783531 189 | 187 8.75879967556 -23.9541911188 190 | 188 7.03195915152 24.9135531926 191 | 189 21.0834457117 -14.3019324915 192 | 190 -23.2664471392 10.9467963715 193 | 191 24.2753624704 7.32457834638 194 | 192 25.0501839623 -4.28031358113 195 | 193 -16.9073531194 18.9829978203 196 | 194 1.89079610001 -25.0452673032 197 | 195 25.4042475481 4.27424239619 198 | 196 -5.29837546831 25.1244268025 199 | 197 11.2396583009 -22.9475330298 200 | 198 15.8959841077 19.6845396746 201 | 199 -15.130087154 20.0639319574 202 | 200 0.284146614062 -25.7274733974 203 | 201 24.3442620738 7.27628256455 204 | 202 4.4642202902 24.9805659416 205 | 203 8.01653207687 -24.5641202691 206 | 204 21.186227725 13.3558395399 207 | 205 -24.9081792692 -6.29910732391 208 | 206 -5.13621628478 24.6272967095 209 | 207 25.1735833278 4.3782412805 210 | 208 4.13857750308 24.6749995683 211 | 209 -25.143800033 -5.36125160559 212 | 210 -10.6090012425 -23.6049522013 213 | 211 23.0537223325 10.7198469564 214 | 212 24.8600578425 4.67703450253 215 | 213 13.4400325174 -21.8313231685 216 | 214 22.8941275457 11.2324727078 217 | 215 25.1114801417 -0.148014336572 218 | 216 -13.5874476858 -22.1276192519 219 | 217 22.2988211546 -12.9593003841 220 | 218 -11.2262716321 22.8418327077 221 | 219 -23.5767069962 -8.8655760443 222 | 220 14.3338255353 20.9718069222 223 | 221 -3.18860905347 -24.9443120795 224 | 222 -11.6199538415 22.9519423003 225 | 223 -15.1661109028 -20.8450364745 226 | 224 -19.788278919 -16.7007164749 227 | 225 25.5519427428 4.44263295216 228 | 226 7.59233230265 -24.5429016094 229 | 227 -25.2965036346 -5.6681051138 230 | 228 0.214929272241 25.9598967156 231 | 229 -7.05355180043 -24.70464321 232 | 230 25.668995584 0.000386426161091 233 | 231 2.88313970448 25.2253374606 234 | 232 -3.98064871128 -25.1637461057 235 | 233 -10.8091431041 23.1775426999 236 | 234 -3.4665151927 25.1284699308 237 | 235 1.19032079088 -25.2571092837 238 | 236 25.0004032483 -2.41599191467 239 | 237 14.6141576078 -21.1746033995 240 | 238 11.7780141011 22.2683834562 241 | 239 10.6664531245 -22.7916109849 242 | 240 25.5009203628 -3.02960110635 243 | 241 -17.3168819769 -18.4132365716 244 | 242 -23.7924777941 9.25488499955 245 | 243 -25.8050759068 -0.656959631917 246 | 244 24.9764116481 -6.8215138056 247 | 245 -5.83900781672 24.4836692053 248 | 246 2.63102209824 25.5335607473 249 | 247 -24.7815646841 7.06360428813 250 | 248 20.6500427432 15.6404280355 251 | 249 -22.9729033183 -11.4000888695 252 | 250 -23.5917516038 -8.864683657 253 | 251 -21.4514692406 -13.7995316354 254 | 252 -0.0588280182045 -25.64746325 255 | 253 23.7801663845 9.64506764278 256 | 254 -13.1312225939 21.3351785079 257 | 255 24.0764548883 9.29041917159 258 | 256 24.9875981968 5.96384653203 259 | 257 0.464597906053 -25.1145482555 260 | 258 25.0188969585 -4.08141955436 261 | 259 -24.501116615 -8.21392065412 262 | 260 -0.00451634679099 -25.4261642866 263 | 261 14.3239271364 20.6177973511 264 | 262 -21.4102783998 -13.2519800171 265 | 263 -7.01513039508 -24.5973588395 266 | 264 23.8144584505 -9.586297028 267 | 265 24.2603981368 8.3934145823 268 | 266 -19.9987743208 -15.85872935 269 | 267 -25.0686022093 3.31669630386 270 | 268 3.68279118826 24.7984444429 271 | 269 -20.9515458473 13.8314131625 272 | 270 -10.7449021016 23.3709006084 273 | 271 -17.240428833 -18.1483814047 274 | 272 -9.23091626989 -24.0701370726 275 | 273 14.6628930289 -20.8186619122 276 | 274 2.27265656726 25.2477944146 277 | 275 -19.3122604614 16.5423749017 278 | 276 20.0945027945 16.1071650753 279 | 277 7.1215446281 24.915455181 280 | 278 24.6553236121 -4.3810152393 281 | 279 20.904034035 15.0257226741 282 | 280 -25.1860338606 -3.25865980466 283 | 281 -21.9953632531 -13.0538588689 284 | 282 -15.287238799 -20.914495557 285 | 283 23.4327785093 -10.2712609115 286 | 284 -16.6331486703 19.8372560932 287 | 285 20.8752738639 14.6257310724 288 | 286 22.0033043593 12.3196762485 289 | 287 -19.3590397658 16.7437006104 290 | 288 -22.2128973755 -12.4910184656 291 | 289 25.3141890633 2.86706265208 292 | 290 24.7391427645 -7.10362842225 293 | 291 25.4769059661 -0.423657811984 294 | 292 -13.5689202944 -21.7645502169 295 | 293 -23.1321776848 11.575618939 296 | 294 -19.998785541 -15.5862124213 297 | 295 25.0152474053 7.00408003988 298 | 296 -25.8202356741 -2.61042094841 299 | 297 -2.373392568 -25.5380621959 300 | 298 21.5971697624 12.9713069625 301 | 299 -25.7203786551 -3.66253553838 302 | 300 -21.9886110313 -12.5417110661 303 | 301 -18.8135465329 -17.5618581205 304 | 302 25.110402793 0.548593935671 305 | 303 24.1182193171 -7.95352222194 306 | 304 7.6817765861 -24.4664377159 307 | 305 -24.5110224714 -6.3587744878 308 | 306 25.355268338 -2.69128234231 309 | 307 13.9054082122 -21.1929577983 310 | 308 -17.5856373884 -19.1127709056 311 | 309 -19.7995593966 16.5141692093 312 | 310 23.9738330296 7.28499005021 313 | 311 11.2600317007 -22.3967103686 314 | 312 25.0642835548 -1.70382375457 315 | 313 -24.2921142633 7.17298141616 316 | 314 12.3986087479 -21.9482452122 317 | 315 -22.1727874128 -11.8409147784 318 | 316 16.2048887562 19.5080271098 319 | 317 12.1047055066 22.5170799185 320 | 318 13.3164229506 -21.8155700062 321 | 319 -23.6189737113 -9.25842310252 322 | 320 20.8124893517 -14.4477355912 323 | 321 -13.8582548835 21.7474124706 324 | 322 -23.0544889004 -11.777912634 325 | 323 14.9768439578 21.2282486658 326 | 324 -21.6354497778 13.00550841 327 | 325 -6.89077116211 -24.8395051056 328 | 326 -4.01509974988 -25.2241369206 329 | 327 11.4115882429 -23.1226438638 330 | 328 -7.20882158044 24.5799298552 331 | 329 -11.023819581 23.5284192309 332 | 330 -22.4145522548 11.9394892354 333 | 331 10.2442198851 -22.8985257514 334 | 332 -15.210321258 20.4092794049 335 | 333 -19.4888627453 16.360710953 336 | 334 22.9449656186 11.6057055988 337 | 335 22.0864024971 13.2211834053 338 | 336 -0.60145925246 -25.4205904475 339 | 337 16.8492119607 18.6185982346 340 | 338 24.3246706741 -8.60167811421 341 | 339 -9.44628388613 -23.1483315804 342 | 340 3.4227796755 -25.0558297059 343 | 341 18.4723423345 17.2793337063 344 | 342 25.0366801915 4.28754086827 345 | 343 16.2740496465 19.1956493807 346 | 344 -16.6993484224 -18.8824423067 347 | 345 16.1064987727 19.2138552363 348 | 346 -14.9651263166 -20.3468900114 349 | 347 -1.03612209165 -25.1907229722 350 | 348 1.67934809704 -24.9683403382 351 | 349 18.1952103921 -18.1111476069 352 | 350 -9.87677681888 -23.1440116654 353 | 351 20.4750604345 -15.3127785057 354 | 352 -22.2396544047 -11.8102349049 355 | 353 -22.5964282071 -11.8236037921 356 | 354 -25.4132748693 -0.230772544654 357 | 355 10.5988700683 23.4239627259 358 | 356 -0.713364970944 -25.1271178329 359 | 357 -24.9333644792 -6.1159458319 360 | 358 -13.5834749027 21.1515362057 361 | 359 1.65108673096 25.0107201853 362 | 360 -15.4947345998 -20.683571234 363 | 361 23.6864642942 -8.4240686665 364 | 362 13.1850733763 22.1009859243 365 | 363 -16.9989706652 19.4668185162 366 | 364 7.64329026676 24.5666716465 367 | 365 21.8408762131 -12.7073422485 368 | 366 23.8693949432 7.61855182171 369 | 367 7.90082774261 -23.9419317744 370 | 368 -14.8262250019 20.8209410725 371 | 369 -12.1002308517 22.1666717009 372 | 370 -24.2859539232 8.83523654784 373 | 371 8.2608902662 23.9875313172 374 | 372 -16.6940247189 -19.2776476304 375 | 373 -15.1837381614 20.51640833 376 | 374 17.5405265394 18.8942513617 377 | 375 12.8627524196 -22.4212605117 378 | 376 4.55307357743 25.4064182966 379 | 377 25.6174875386 4.34137949468 380 | 378 -13.9089116955 21.395334786 381 | 379 -1.78440423674 -25.5372469853 382 | 380 -8.7781524043 -23.8167270584 383 | 381 24.2513587762 9.1820628493 384 | 382 -7.00427237236 -24.6587938753 385 | 383 -18.9901244225 -17.2489825583 386 | 384 -25.4520616837 -4.33461059502 387 | 385 -5.31869247183 24.99577164 388 | 386 -6.93079394384 24.7776890165 389 | 387 5.60425702799 24.9722186774 390 | 388 -4.28261858878 25.1532864374 391 | 389 -24.7108710433 -4.16104037705 392 | 390 -23.7216574202 10.0897203129 393 | 391 15.3034974298 20.7817527196 394 | 392 -24.2268661605 -6.95922244694 395 | 393 -6.50781676679 25.1643005564 396 | 394 25.0276835096 -5.86471921864 397 | 395 -23.6023972102 -9.15321752721 398 | 396 9.52632323221 24.0660104343 399 | 397 11.0587505957 -23.1696726464 400 | 398 12.9919505208 -21.9197561273 401 | 399 -23.8904519495 -8.8448788731 402 | 400 14.1369092452 -21.0905161268 403 | 401 18.4773748152 -16.8706735586 404 | 402 -11.0517740587 22.7826747013 405 | 403 19.3492232923 17.1697798122 406 | 404 -25.052210985 -6.8617827021 407 | 405 16.7839714422 -18.9479942397 408 | 406 -21.7160997617 14.0081667898 409 | 407 22.9781909906 10.5878844817 410 | 408 -14.70115844 -20.7208049251 411 | 409 -14.2027702091 -21.0350435053 412 | 410 -25.4067430224 1.22646418009 413 | 411 -9.64989319426 24.0856908868 414 | 412 24.0595218575 7.37121348931 415 | 413 -20.9622832777 14.5185859579 416 | 414 7.27981755638 -24.4493865507 417 | 415 -24.064485159 6.87188069955 418 | 416 4.57945248585 24.7012210146 419 | 417 -17.8806293655 18.8256289708 420 | 418 -16.233779631 19.4924594185 421 | 419 25.7386795128 -1.34070658864 422 | 420 0.460153655544 25.0562663129 423 | 421 -23.4967298247 -10.1726712098 424 | 422 5.33303206255 24.7622300714 425 | 423 16.3001753574 19.2306787687 426 | 424 2.89870036457 -24.9900343325 427 | 425 25.0615374318 1.06284946269 428 | 426 -16.0702084475 20.2897949696 429 | 427 23.9005744328 8.20189556114 430 | 428 -19.8074254759 15.7843335566 431 | 429 7.44237168489 24.1185889937 432 | 430 -23.2144733612 9.87362768935 433 | 431 22.2062864585 13.3091573243 434 | 432 12.7396368068 21.5428630972 435 | 433 20.1828031865 -16.356626049 436 | 434 -16.9324539061 -19.5484515813 437 | 435 3.71777304951 25.7319713972 438 | 436 -18.7655708817 17.5112472025 439 | 437 23.4095078277 8.85428868852 440 | 438 0.107129117335 25.2236267601 441 | 439 24.3240845775 -8.17699593791 442 | 440 -15.3316464567 -20.0106237587 443 | 441 19.6256762647 16.102362847 444 | 442 17.8950752266 -17.8781379378 445 | 443 -12.9859109847 22.503277128 446 | 444 11.977772935 -22.5778030013 447 | 445 21.9544450765 -12.6674004885 448 | 446 18.2620425572 17.747012846 449 | 447 21.8814818086 13.1940545379 450 | 448 -23.9537341508 -9.74500265864 451 | 449 -25.2710725036 5.56618896195 452 | 450 -24.189744818 -8.64423807652 453 | 451 -25.380574258 4.58865365085 454 | 452 -1.8863517446 25.3785387281 455 | 453 12.7737548911 -21.7908193826 456 | 454 3.05756383736 24.8807536004 457 | 455 -16.7169508683 -18.938333511 458 | 456 -25.1459296916 -1.22236233465 459 | 457 25.0915472733 1.46150451471 460 | 458 25.1697490135 -5.38333017728 461 | 459 21.0559943535 -14.6645286499 462 | 460 9.21252212271 23.8188429169 463 | 461 -23.6070927141 9.44105153607 464 | 462 25.6366147081 3.56393004167 465 | 463 14.8508864069 -21.2546714293 466 | 464 -12.0196121359 22.9907712877 467 | 465 -13.6033941635 -21.0214503876 468 | 466 -2.88364666219 -24.9793805065 469 | 467 -24.496931816 5.35971626491 470 | 468 -2.10262820095 -25.190578271 471 | 469 -2.80137139667 25.1728670491 472 | 470 -20.9738945406 15.3433192467 473 | 471 -1.91771323916 -25.0357950847 474 | 472 18.6367786386 17.2837410516 475 | 473 -7.32839140928 -24.5965109824 476 | 474 24.8134921303 3.79471641249 477 | 475 -19.5397707244 15.7041378362 478 | 476 -24.9899965401 2.52431218672 479 | 477 7.36303529171 24.3398221223 480 | 478 -6.12615762075 -24.550520804 481 | 479 21.4231184221 -12.9677001231 482 | 480 -0.308364522695 -25.1217926119 483 | 481 14.5241767533 -20.8433668163 484 | 482 -13.6653258779 -21.5894490451 485 | 483 -22.2718814991 12.4122815414 486 | 484 9.21522948171 23.3978111923 487 | 485 -24.8366772458 -7.53367701476 488 | 486 -2.13573229524 -25.6841356396 489 | 487 22.6342653941 -10.7399534159 490 | 488 -25.5356590649 -1.14538546177 491 | 489 -15.0514639117 -20.655342099 492 | 490 -14.9035057641 -21.1119422463 493 | 491 -15.19884261 20.6494514485 494 | 492 5.11957220728 24.5160585117 495 | 493 -9.46551868737 -23.267721725 496 | 494 -9.83428631774 -23.9038787467 497 | 495 2.27358243777 25.7481865325 498 | 496 -24.2402355667 8.80704208685 499 | 497 0.713219734095 25.6274746716 500 | 498 -14.2399189041 -20.8761241841 501 | 499 24.7071578862 -6.68630886782 502 | 500 -14.2212088284 -21.6059991863 503 | 501 -0.103361066079 -2.64109314801 504 | 502 2.34825025072 0.92537578063 505 | 503 1.55512823017 1.94129274226 506 | 504 2.09468729175 1.49416634457 507 | 505 1.9658136065 1.94246735676 508 | 506 1.85297873716 -2.34945919189 509 | 507 0.795311402459 -2.26717658579 510 | 508 1.41461524776 -2.43097669119 511 | 509 -2.10811271683 2.07624509503 512 | 510 -0.0658229579055 2.63500040508 513 | 511 -0.780169397658 2.85944889844 514 | 512 1.21886483121 2.29715410299 515 | 513 -1.0123219052 2.39811234878 516 | 514 -0.423219079229 2.63139186699 517 | 515 0.0477426093696 2.1091323377 518 | 516 2.32205382446 0.882997140267 519 | 517 -0.447347561644 -2.02723181557 520 | 518 -2.0268969039 0.477939642532 521 | 519 -0.843176109122 -2.34359039115 522 | 520 2.05960390527 1.58013364737 523 | 521 -2.03215532532 -2.089605413 524 | 522 0.677264897283 -2.29287225134 525 | 523 0.252517621676 2.11283404577 526 | 524 -1.69716484218 -1.37330519012 527 | 525 -1.6900571991 -1.29469094925 528 | 526 1.0458760608 2.39258494093 529 | 527 2.03931208241 2.01468174499 530 | 528 1.74614737978 -1.49480068934 531 | 529 -0.931230844436 -2.06087784563 532 | 530 0.287259307928 -2.88223930424 533 | 531 -2.83362269466 -0.396783771618 534 | 532 1.65436186533 -2.2109842857 535 | 533 -1.50588183633 1.65928901958 536 | 534 -2.44806064755 0.406272695129 537 | 535 -0.205742475789 -2.54221287105 538 | 536 2.07984093106 0.592856493083 539 | 537 0.964001923463 -2.24288971486 540 | 538 -2.55031596947 -1.55885804226 541 | 539 0.128631266462 2.63275346445 542 | 540 0.247897860243 -2.37920033703 543 | 541 0.342131521164 2.21995749963 544 | 542 1.23735882308 -2.04412461969 545 | 543 -2.57659733346 1.18305238786 546 | 544 1.91548293474 1.80674980723 547 | 545 1.82289629925 -0.89211535365 548 | 546 -1.2410656775 2.20110560933 549 | 547 -2.22965808106 0.655649213074 550 | 548 2.10512944599 -1.02994474372 551 | 549 1.37487937781 2.04450712725 552 | 550 -0.654826107128 -2.44949578724 553 | 551 1.57587627012 -1.47321877303 554 | 552 -1.46643849002 -2.01697253087 555 | 553 -0.666226991606 -2.7886454172 556 | 554 -2.16293784906 1.92682365765 557 | 555 2.18164494665 -2.00617189726 558 | 556 -0.280771994354 2.92125410727 559 | 557 1.32817310867 2.05727355368 560 | 558 -2.22964834065 -0.935387079167 561 | 559 1.48655772414 -1.54212265206 562 | 560 -1.88774255638 -1.26222119287 563 | 561 -2.52580158107 -0.366213906735 564 | 562 2.9002542634 -0.519644633087 565 | 563 -2.5357976247 -0.121137883579 566 | 564 -2.2538351652 0.718532058403 567 | 565 -2.09636449026 -0.463529380568 568 | 566 2.0075425268 1.32850546767 569 | 567 2.21056582083 -1.59630074298 570 | 568 -2.53507661018 1.01550448398 571 | 569 -2.19420807761 -1.98835697044 572 | 570 1.32301772193 1.59554794422 573 | 571 -1.53312548834 -2.09364365479 574 | 572 2.45330701308 0.0858595775915 575 | 573 2.39063948641 -1.64018890507 576 | 574 2.21106460576 -0.893510707444 577 | 575 -0.711063433249 2.28131005896 578 | 576 -1.67368169916 -1.43076346235 579 | 577 -1.01927789818 -2.45205924405 580 | 578 -0.748517970057 -2.21994775528 581 | 579 0.285163576145 2.18802863028 582 | 580 -2.09259464868 -0.0551085209529 583 | 581 -1.86141015293 -1.57469480891 584 | 582 1.12062728533 2.06016652161 585 | 583 -1.74776830008 -2.09598646449 586 | 584 -0.256239781296 2.87958787381 587 | 585 -1.90722347199 -1.85176975519 588 | 586 2.39543116375 -0.390526384191 589 | 587 -2.40714472442 1.26689259317 590 | 588 -2.44558582424 0.948867001757 591 | 589 -2.16745739702 1.59660815185 592 | 590 1.90049405567 1.31721770131 593 | 591 0.0542306723132 -2.00030857734 594 | 592 1.88545664212 0.77345166284 595 | 593 0.423766688151 2.76660353823 596 | 594 -1.82174145026 1.13242749008 597 | 595 -2.80833367104 0.423939753209 598 | 596 1.76118484623 -1.74895670396 599 | 597 1.98206568692 -1.91868402625 600 | 598 -2.27097647208 -0.0455617268562 601 | 599 -2.00662612352 -0.742717336762 602 | 600 1.58355172159 2.53410314966 603 | 601 2.29447502929 -0.102928710727 604 | 602 -2.51807320158 -0.354310504116 605 | 603 0.496041896171 2.73073787317 606 | 604 2.39338207973 -0.586804138584 607 | 605 2.2148670184 1.9155965292 608 | 606 1.55093807517 -2.14590425391 609 | 607 -2.59101132484 -0.027519768551 610 | 608 -1.1199823922 2.70706755497 611 | 609 2.29892216412 -1.62652617189 612 | 610 -1.16708948238 2.47923297359 613 | 611 -2.49125089796 -0.234708335705 614 | 612 2.43343743512 -1.60409818378 615 | 613 0.243407576165 -2.02410160814 616 | 614 -2.04772572319 1.75882030939 617 | 615 -1.75798048839 1.29062325841 618 | 616 -2.06857062984 -0.169975410076 619 | 617 -2.87685580255 0.581941655492 620 | 618 1.32276286579 -2.40601572064 621 | 619 0.88750947094 2.29520739808 622 | 620 -0.516811421274 -2.34606179637 623 | 621 -2.47873743508 -1.24378846733 624 | 622 1.82344822159 -1.56034001091 625 | 623 -0.252687547811 -2.34638289657 626 | 624 -1.29725899033 2.24134421642 627 | 625 -1.63197426879 -1.2646424233 628 | 626 -2.89039572918 0.509264265042 629 | 627 0.191106049164 -2.42214748098 630 | 628 0.954674660069 1.97675699168 631 | 629 -2.07901849551 -1.13936526267 632 | 630 -0.280524144664 2.82506247262 633 | 631 0.578926171585 -2.16896027909 634 | 632 1.22114731015 2.65222868893 635 | 633 -2.04939948186 2.08773320595 636 | 634 -2.55686524831 -0.0322902189424 637 | 635 0.33967755595 2.71960135422 638 | 636 0.183950618685 2.33024938583 639 | 637 -2.6674037448 0.0232263741038 640 | 638 1.14911464889 -1.75785725638 641 | 639 2.62722255799 -0.883028660554 642 | 640 -0.630247814907 -2.55211716003 643 | 641 -0.663685369812 1.92259489429 644 | 642 0.032466901566 -2.01792791113 645 | 643 -2.4928918692 0.825942740634 646 | 644 -0.366913598914 -2.11868382083 647 | 645 -2.34640530551 1.21337320486 648 | 646 -1.38364377027 2.63324244782 649 | 647 -2.1406711776 -1.53550486822 650 | 648 1.63781361064 -1.19777504243 651 | 649 -0.952211870974 -1.98721798186 652 | 650 2.06191116288 1.30445190436 653 | 651 2.00335825367 -0.383224910704 654 | 652 -1.37574473571 -1.94069866929 655 | 653 1.55452622902 2.29738342884 656 | 654 1.33193920367 -2.34734777584 657 | 655 -2.47808236678 0.00917700449491 658 | 656 -2.39959886445 -1.22800898859 659 | 657 2.26121721652 -0.494340100533 660 | 658 -1.26179449097 -2.43368639441 661 | 659 2.44170849061 -0.637504506125 662 | 660 -1.98340020849 -2.16410731771 663 | 661 -2.16994010038 1.63969556865 664 | 662 2.03440743519 -1.92084495691 665 | 663 -2.95549798131 -0.281879361331 666 | 664 -1.93325059884 1.2890471923 667 | 665 2.28551449623 -1.41415745658 668 | 666 -2.21125367863 0.198542175089 669 | 667 2.95204982628 0.22393255376 670 | 668 1.9595815174 -1.94849435528 671 | 669 2.06692348281 1.22277469117 672 | 670 2.685215731 1.26059496581 673 | 671 -0.30906032174 -2.68732399274 674 | 672 2.61329372519 -0.635695808374 675 | 673 0.751772364681 2.722432102 676 | 674 2.01075208382 0.54881334011 677 | 675 -1.42380329791 -2.48682889822 678 | 676 -0.705455073493 -2.51420639885 679 | 677 0.835914474622 -2.30708236383 680 | 678 -1.02519724195 -1.76935514541 681 | 679 -1.83553974474 -1.7198698652 682 | 680 -1.63970447398 1.29968681672 683 | 681 -1.65914041568 2.24475763114 684 | 682 1.01755069716 -2.79679446532 685 | 683 -1.06411230916 -1.73315200729 686 | 684 -1.33643053048 1.9995792336 687 | 685 -2.09538671659 0.100353285321 688 | 686 2.71531523756 0.896178036172 689 | 687 1.97520846896 0.93383533363 690 | 688 -0.802231327249 -1.85334231193 691 | 689 1.79639962887 1.72938083633 692 | 690 -2.46322948667 0.459043738834 693 | 691 -1.72822519828 1.30548558228 694 | 692 -2.37902083469 -1.06699274107 695 | 693 -2.18532480393 1.69443921825 696 | 694 -0.519330380847 -2.66570723645 697 | 695 -0.554881871632 -2.02787844788 698 | 696 -1.35082996872 2.23851041083 699 | 697 0.382607321265 -2.1341161576 700 | 698 -0.436884272857 -2.28882468306 701 | 699 -2.40527180146 0.383576854847 702 | 700 -2.33893435897 0.692391805852 703 | 701 0.189810135282 -2.63797057527 704 | 702 -1.24513195507 -1.89104418961 705 | 703 -2.39954892685 0.128234078938 706 | 704 -2.09198575714 -0.414421368855 707 | 705 0.661136860861 1.9551019019 708 | 706 2.12113715643 0.187311619006 709 | 707 -2.11331295649 2.02862079707 710 | 708 -0.0689273940004 -2.11963283085 711 | 709 -1.21430017999 2.06333726524 712 | 710 -1.8092626383 -1.33240838882 713 | 711 0.302566989958 2.4849536488 714 | 712 -0.484752835432 -2.29466741954 715 | 713 -2.17718399857 -0.217363855935 716 | 714 0.355790322933 2.78802376838 717 | 715 -0.668593204968 -2.7426984626 718 | 716 1.72168400751 -2.24846639036 719 | 717 2.09662189428 0.876640743042 720 | 718 -2.38453548273 -1.26238705856 721 | 719 0.876037397262 -2.78396019259 722 | 720 -2.20138638721 1.63300739205 723 | 721 -2.83631343741 0.933574503711 724 | 722 2.13020178216 0.641123663089 725 | 723 2.87460789065 0.506564768052 726 | 724 -1.80490915665 -1.08583231759 727 | 725 1.42779078107 -2.0471142004 728 | 726 1.22702486541 -2.46356370931 729 | 727 -2.1610159049 -1.51268006339 730 | 728 2.04576900393 1.44606304047 731 | 729 -1.43724247509 1.41730326428 732 | 730 0.907868738765 -2.17400632877 733 | 731 -1.28733082849 -2.06338196391 734 | 732 -2.69067818407 -0.378824986894 735 | 733 0.19250212578 2.74452659225 736 | 734 -2.24851367532 -0.943786236771 737 | 735 -0.598489063964 2.92016454115 738 | 736 -0.527114333816 -2.70731276996 739 | 737 0.551565925165 2.59336572305 740 | 738 0.687815438147 2.04456646239 741 | 739 -1.12192832132 -2.06160578442 742 | 740 1.92147379311 1.10494954067 743 | 741 -2.01932330217 0.946982447626 744 | 742 -1.97628804433 -0.731590022266 745 | 743 -2.15420175937 -0.911676445853 746 | 744 -2.33204263104 -0.87156687631 747 | 745 0.814195059638 2.09097560196 748 | 746 2.71973666056 -0.906556154128 749 | 747 1.43428215853 -2.04990969642 750 | 748 1.63817918569 2.09345923546 751 | 749 -2.8835792926 -0.42708695515 752 | 750 2.47010812895 -1.13933403682 753 | 751 1.54798368726 -2.52764349431 754 | 752 -1.46286518089 1.92617872724 755 | 753 -1.29047835356 2.54748030354 756 | 754 1.39791915072 -1.50217360603 757 | 755 -2.0181272501 -1.92922324591 758 | 756 1.19579665659 2.29729656171 759 | 757 1.74769517366 -1.56988954387 760 | 758 -0.478254598341 2.01823021163 761 | 759 -2.16956324443 1.77282671285 762 | 760 -1.00677950246 -1.79507255131 763 | 761 1.66459642637 2.05329055019 764 | 762 2.28664729421 1.41978960654 765 | 763 1.85541957336 1.84686428832 766 | 764 -1.12006669279 2.73876555644 767 | 765 0.776968182413 1.88603001843 768 | 766 -1.62408096699 -1.70287071209 769 | 767 2.26384327712 1.46128804758 770 | 768 2.09157132778 -1.44537798677 771 | 769 -1.36061989628 1.56880105098 772 | 770 1.22067585435 -1.83598688287 773 | 771 2.67959143284 0.385248296253 774 | 772 2.01938282563 -0.0300833919348 775 | 773 -1.24939249069 -2.13092072246 776 | 774 -0.716313434104 -2.09494419875 777 | 775 -1.60431108291 -2.43082922812 778 | 776 2.18711921675 -1.86071310349 779 | 777 2.46859756618 -0.209992466516 780 | 778 2.31510124222 1.08000517651 781 | 779 -2.30796727218 0.919643355809 782 | 780 1.79652525248 0.927743574405 783 | 781 1.82349182202 -1.35047870106 784 | 782 0.566135718024 2.29246369606 785 | 783 2.19118599682 1.57322224349 786 | 784 2.4563443154 -1.70882713861 787 | 785 -1.61818430537 2.45183698326 788 | 786 2.35704932589 -0.528619977573 789 | 787 1.96571360934 -1.37240623825 790 | 788 -1.26206420623 -2.06255405099 791 | 789 -2.60619255439 0.435438168722 792 | 790 -1.95427587267 0.737924231749 793 | 791 -2.14156500533 1.01446198524 794 | 792 1.97229692446 -0.472724825589 795 | 793 -0.458735600107 -2.83989090978 796 | 794 -1.77280100853 -2.34959049379 797 | 795 -1.74790933666 -2.36870674136 798 | 796 -1.48184942668 -2.50610890476 799 | 797 -0.619485398721 2.16242265923 800 | 798 -1.75014039436 1.8563106216 801 | 799 0.362509541187 -2.51940673618 802 | 800 -2.0639546427 -2.12515876411 803 | 801 0.0586700408482 2.56705148058 804 | 802 1.96826039803 -1.33549910048 805 | 803 0.435949818897 -2.44001678921 806 | 804 1.92592819449 0.850989794387 807 | 805 2.15550185227 1.31394601106 808 | 806 -2.82167573885 -0.620644469678 809 | 807 -2.39555839938 -0.74238765529 810 | 808 0.337623422375 2.87886915327 811 | 809 -2.00757075285 -0.0736630937629 812 | 810 2.45856608937 -0.19209714263 813 | 811 1.06882269644 2.38101565597 814 | 812 -1.61930704027 1.33633375986 815 | 813 2.37721601813 -0.164345127961 816 | 814 0.9908338285 2.71595318532 817 | 815 -0.670208676599 -2.82638278359 818 | 816 1.43810441454 -1.82978511726 819 | 817 -1.02726568365 1.89282624909 820 | 818 -0.371467559875 2.05449478639 821 | 819 1.66272193687 1.96570516053 822 | 820 -0.607961654347 -2.18969565124 823 | 821 -0.854921304007 1.90563949454 824 | 822 -1.29752947041 -1.58594079225 825 | 823 -2.14653768686 1.07740201787 826 | 824 -0.804972729162 -2.12993493001 827 | 825 -1.57212546156 2.33276458375 828 | 826 -1.4192300774 -2.34365779331 829 | 827 1.85743278101 -1.49491789115 830 | 828 0.118427242225 2.53096386784 831 | 829 -2.33068672375 1.57871837421 832 | 830 -0.0492245874969 2.3097214116 833 | 831 -2.13562992271 0.18840800995 834 | 832 2.84712243073 -0.294196779504 835 | 833 -2.08306940061 0.756756350482 836 | 834 -2.537477081 0.0647482055918 837 | 835 1.49306313564 -2.52027284136 838 | 836 -1.99994309186 1.53612503611 839 | 837 0.415656354495 -2.32679872437 840 | 838 0.579325189733 2.17691553857 841 | 839 -2.49135741971 -1.47074108994 842 | 840 -1.81136627422 2.11994544599 843 | 841 2.68828892334 -0.646163051447 844 | 842 -1.43714258346 1.71255671698 845 | 843 -1.23171692358 2.43702997744 846 | 844 2.01234585915 1.2330748405 847 | 845 -2.70509843762 0.988235717952 848 | 846 2.60282632081 0.598075450775 849 | 847 0.723954251701 2.12075729929 850 | 848 -2.55326983764 -1.57118879809 851 | 849 -0.680027525192 2.23963172172 852 | 850 -2.28608679748 -0.886206944722 853 | 851 -1.27657686593 2.46219616325 854 | 852 -1.22947222875 2.52381741273 855 | 853 -1.44150756645 1.74499867308 856 | 854 0.957853509124 -1.80766993596 857 | 855 1.32106104564 -1.98670453936 858 | 856 -2.29944282556 -1.77313687089 859 | 857 -0.382108752643 2.76420170402 860 | 858 -1.67777977302 2.19207425331 861 | 859 -1.83947010393 -1.71867958031 862 | 860 0.130625064337 -2.72509381505 863 | 861 1.14312654575 1.74333891589 864 | 862 -0.217400207689 -2.56517503278 865 | 863 -0.795043905995 1.90650872645 866 | 864 -2.55649314682 -0.919119290032 867 | 865 2.33025253149 -1.3301309632 868 | 866 0.392461129297 2.18918361182 869 | 867 -0.401737055942 -2.23251369651 870 | 868 1.14887583413 2.48206856846 871 | 869 0.292790153948 2.39473385664 872 | 870 0.0298239223925 2.6785114932 873 | 871 -0.744863395877 2.60226738115 874 | 872 -0.00467936675909 2.77391859282 875 | 873 2.45431039802 -1.50041369852 876 | 874 0.56790940438 -1.96315017461 877 | 875 2.81752892575 -0.437003907728 878 | 876 -1.77173483625 -1.20625366374 879 | 877 1.84129501106 -2.29198114536 880 | 878 -1.66806159914 -1.62509923999 881 | 879 2.39788688117 1.25340180283 882 | 880 -2.32649293721 -0.159455638641 883 | 881 1.57610455566 1.52122865656 884 | 882 0.953045742799 2.71968248794 885 | 883 -0.848525037907 -2.21848678058 886 | 884 -2.19180305898 -1.86044934077 887 | 885 -2.06840103672 -1.69799630814 888 | 886 -2.63460217986 -0.191214383305 889 | 887 -2.29091006048 -0.265685567346 890 | 888 -0.105678103776 -2.17767470307 891 | 889 -2.27590562531 -0.0611467787771 892 | 890 2.85587015128 0.418358330008 893 | 891 0.0289676951701 -2.54014893749 894 | 892 -1.97848836914 -1.10834595081 895 | 893 1.8033996514 2.2871478094 896 | 894 -2.60635682488 -0.205348411066 897 | 895 -1.87778144484 -1.81237474343 898 | 896 -1.70056038626 -1.1897231728 899 | 897 2.25404641703 1.65297537172 900 | 898 -1.42598808553 2.45804263616 901 | 899 -2.09913245822 0.0106183649039 902 | 900 -1.20749466383 2.68726019004 903 | 901 2.36896902208 -1.6238499582 904 | 902 2.32781465367 0.948262188376 905 | 903 -0.542514105496 -2.43081889648 906 | 904 1.64444232 2.06780011387 907 | 905 -1.07869647541 -2.58962188864 908 | 906 2.06272448951 -1.95167740647 909 | 907 2.28763055426 -1.06495824808 910 | 908 2.25586142492 -1.38756208624 911 | 909 2.53229600201 0.13873001057 912 | 910 -1.34082340151 2.48591623863 913 | 911 -2.51310359003 0.33312384122 914 | 912 -1.22696877126 1.76321256729 915 | 913 -1.15696243048 -2.3675918084 916 | 914 -1.27256113269 1.56240426236 917 | 915 -2.25710840893 -0.662407169522 918 | 916 -0.571293454038 2.49553029809 919 | 917 0.797966937002 2.63568643604 920 | 918 -1.73557517789 1.16436915859 921 | 919 2.48042147074 -0.240906313029 922 | 920 -1.68990602308 -2.09907138296 923 | 921 2.2020429338 -1.64981169246 924 | 922 -1.84035742702 0.897169346988 925 | 923 -1.62866970227 1.77878943049 926 | 924 1.05435590565 2.65218776882 927 | 925 2.44329905505 1.03414911213 928 | 926 -2.33753956261 1.63689799525 929 | 927 -2.0520197324 -0.269240263491 930 | 928 -2.55461724277 0.370880615161 931 | 929 -0.715945724799 2.12704053573 932 | 930 2.19522301526 0.159013868812 933 | 931 1.12307997906 -2.34784983533 934 | 932 -2.27506799264 1.43533649941 935 | 933 -0.896090099639 -2.6040472324 936 | 934 2.55368291286 0.48768447114 937 | 935 -0.344243756663 2.15074501016 938 | 936 -2.6160544934 -0.789409448604 939 | 937 1.97235417564 -1.49136038221 940 | 938 -0.43017502951 2.85924477723 941 | 939 -1.58276063044 -1.78743561613 942 | 940 -0.434131472474 2.80603231015 943 | 941 1.17469991321 1.65014757761 944 | 942 2.27218881395 0.572204926095 945 | 943 2.54559448823 -0.0617786963664 946 | 944 0.435669469405 2.16047774549 947 | 945 -0.384319022915 -2.8898282756 948 | 946 -1.47953556281 1.49064766193 949 | 947 -2.11459419818 1.03579465805 950 | 948 0.392539740859 1.97202362519 951 | 949 -0.807722575886 2.50923049713 952 | 950 0.637532070731 -1.94197400948 953 | 951 -0.448863986384 2.16929536838 954 | 952 -0.869338167143 2.17287470074 955 | 953 -2.35028785909 0.234313635622 956 | 954 -2.76428408962 -0.871376563483 957 | 955 0.994078314542 -2.48272247909 958 | 956 1.11520943291 2.25021496044 959 | 957 0.599007452893 2.79038395356 960 | 958 0.289070852843 -2.81717508714 961 | 959 1.65401625669 -1.25862854201 962 | 960 -2.48497276318 1.01147638689 963 | 961 -1.78191357372 1.77902672132 964 | 962 -0.788564106919 1.85890755017 965 | 963 2.0183794171 1.12389978033 966 | 964 -1.794056255 1.95505872559 967 | 965 -0.415799376374 2.43756507785 968 | 966 2.27024008511 0.160935581179 969 | 967 1.85578861922 -1.21500663341 970 | 968 -1.55803830268 -2.00493205191 971 | 969 2.51979897177 1.40076131044 972 | 970 2.6411861557 -0.11722357031 973 | 971 0.407325896364 -2.52548083805 974 | 972 -1.97208700928 -0.463256361516 975 | 973 2.8954457225 -0.379205412188 976 | 974 -1.436521217 2.07541128953 977 | 975 -0.826769230977 -2.42430730158 978 | 976 -2.07199705106 -1.37776214266 979 | 977 1.18854715747 -1.87805020834 980 | 978 -2.26166503687 -0.196462147313 981 | 979 -1.11669276912 2.26674193136 982 | 980 2.69286281556 0.723784232139 983 | 981 -0.240792911447 -2.1091773413 984 | 982 -2.36274970399 0.976610862529 985 | 983 -1.41331369979 1.46369082598 986 | 984 2.48497399808 -1.19011357138 987 | 985 1.49406249438 -2.59331698048 988 | 986 2.13335954849 1.28440341959 989 | 987 2.63546214029 -0.179893780179 990 | 988 -1.03820834669 -2.32816126483 991 | 989 0.567298713887 2.07753687153 992 | 990 2.3541836015 1.85316563432 993 | 991 0.789749378401 -2.17109949889 994 | 992 -1.0496579872 2.19889120552 995 | 993 -1.15327455245 2.57770960542 996 | 994 2.03066752389 -1.27904847662 997 | 995 0.256944378987 -2.42948137286 998 | 996 -2.32709495969 1.73381293368 999 | 997 0.754290943695 2.03206082705 1000 | 998 -2.50450083456 1.53777329377 1001 | -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_04_code/B04881_chapter04_code02.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "%matplotlib inline\n", 12 | "from pyspark import SparkContext\n", 13 | "from pyspark.sql import SQLContext" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 2, 19 | "metadata": { 20 | "collapsed": false 21 | }, 22 | "outputs": [], 23 | "source": [ 24 | "## spark Context \n", 25 | "sc = SparkContext( 'local', 'pyspark')" 26 | ] 27 | }, 28 | { 29 | "cell_type": "code", 30 | "execution_count": 3, 31 | "metadata": { 32 | "collapsed": false 33 | }, 34 | "outputs": [], 35 | "source": [ 36 | "sqlContext = SQLContext(sc)" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 4, 42 | "metadata": { 43 | "collapsed": true 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "def parse_line(l):\n", 48 | " try:\n", 49 | " return l.split(\",\")\n", 50 | " except:\n", 51 | " print(\"error in processing {0}\".format(l))" 52 | ] 53 | }, 54 | { 55 | "cell_type": "code", 56 | "execution_count": 5, 57 | "metadata": { 58 | "collapsed": false 59 | }, 60 | "outputs": [], 61 | "source": [ 62 | "songs = sc.textFile('/Users/jbabcock/Downloads/YearPredictionMSD.txt').\\\n", 63 | "map(lambda x : parse_line(x)).\\\n", 64 | "toDF()" 65 | ] 66 | }, 67 | { 68 | "cell_type": "code", 69 | "execution_count": 7, 70 | "metadata": { 71 | "collapsed": true 72 | }, 73 | "outputs": [], 74 | "source": [ 75 | "from pyspark.mllib.regression import LabeledPoint\n", 76 | "songs_labeled = songs.map( lambda x: LabeledPoint(x[0],x[1:]) )" 77 | ] 78 | }, 79 | { 80 | "cell_type": "code", 81 | "execution_count": 8, 82 | "metadata": { 83 | "collapsed": false 84 | }, 85 | "outputs": [], 86 | "source": [ 87 | "## splitting train\n", 88 | "\n", 89 | "songs_train = songs_labeled.zipWithIndex().\\\n", 90 | "filter( lambda x: x[1] < 463715).\\\n", 91 | "map( lambda x: x[0] )" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": 9, 97 | "metadata": { 98 | "collapsed": true 99 | }, 100 | "outputs": [], 101 | "source": [ 102 | "## splitting test\n", 103 | "\n", 104 | "songs_test = songs_labeled.zipWithIndex().\\\n", 105 | "filter( lambda x: x[1] >= 463715).\\\n", 106 | "map( lambda x: x[0] )" 107 | ] 108 | }, 109 | { 110 | "cell_type": "code", 111 | "execution_count": 18, 112 | "metadata": { 113 | "collapsed": false 114 | }, 115 | "outputs": [], 116 | "source": [ 117 | "from pyspark.mllib.tree import RandomForest\n", 118 | "rf = RandomForest.trainRegressor(songs_train,{},50,\"auto\",\"variance\",10,32)" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 19, 124 | "metadata": { 125 | "collapsed": true 126 | }, 127 | "outputs": [], 128 | "source": [ 129 | "prediction = rf.predict(songs_test.map(lambda x: x.features))\n", 130 | "predictedObserved = songs_test.map(lambda lp: lp.label).zip(prediction)" 131 | ] 132 | }, 133 | { 134 | "cell_type": "code", 135 | "execution_count": 20, 136 | "metadata": { 137 | "collapsed": false 138 | }, 139 | "outputs": [], 140 | "source": [ 141 | "from pyspark.mllib.evaluation import RegressionMetrics" 142 | ] 143 | }, 144 | { 145 | "cell_type": "code", 146 | "execution_count": 21, 147 | "metadata": { 148 | "collapsed": false 149 | }, 150 | "outputs": [ 151 | { 152 | "data": { 153 | "text/plain": [ 154 | "-3.69830379609341" 155 | ] 156 | }, 157 | "execution_count": 21, 158 | "metadata": {}, 159 | "output_type": "execute_result" 160 | } 161 | ], 162 | "source": [ 163 | "RegressionMetrics(predictedObserved).r2" 164 | ] 165 | }, 166 | { 167 | "cell_type": "code", 168 | "execution_count": 22, 169 | "metadata": { 170 | "collapsed": false 171 | }, 172 | "outputs": [ 173 | { 174 | "data": { 175 | "text/plain": [ 176 | "[(2007.0, 1995.9064460339775),\n", 177 | " (2003.0, 2002.534486616815),\n", 178 | " (2005.0, 1999.4269553417332),\n", 179 | " (2003.0, 2002.2919078641394),\n", 180 | " (2005.0, 2001.720244097928),\n", 181 | " (2007.0, 1997.7955438534639),\n", 182 | " (2003.0, 2000.5908110171194),\n", 183 | " (2003.0, 1999.874075396483),\n", 184 | " (2003.0, 1997.9664817235432),\n", 185 | " (2005.0, 2001.4931432241076)]" 186 | ] 187 | }, 188 | "execution_count": 22, 189 | "metadata": {}, 190 | "output_type": "execute_result" 191 | } 192 | ], 193 | "source": [ 194 | "predictedObserved.take(10)" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": null, 200 | "metadata": { 201 | "collapsed": true 202 | }, 203 | "outputs": [], 204 | "source": [] 205 | } 206 | ], 207 | "metadata": { 208 | "kernelspec": { 209 | "display_name": "Python 2", 210 | "language": "python", 211 | "name": "python2" 212 | }, 213 | "language_info": { 214 | "codemirror_mode": { 215 | "name": "ipython", 216 | "version": 2 217 | }, 218 | "file_extension": ".py", 219 | "mimetype": "text/x-python", 220 | "name": "python", 221 | "nbconvert_exporter": "python", 222 | "pygments_lexer": "ipython2", 223 | "version": "2.7.10" 224 | } 225 | }, 226 | "nbformat": 4, 227 | "nbformat_minor": 0 228 | } 229 | -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_07_code/B04481_chapter_07_code_01.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "%matplotlib inline\n", 12 | "import tensorflow as tf\n", 13 | "import numpy as np" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 2, 19 | "metadata": { 20 | "collapsed": false 21 | }, 22 | "outputs": [ 23 | { 24 | "name": "stdout", 25 | "output_type": "stream", 26 | "text": [ 27 | "Extracting MNIST_data/train-images-idx3-ubyte.gz\n", 28 | "Extracting MNIST_data/train-labels-idx1-ubyte.gz\n", 29 | "Extracting MNIST_data/t10k-images-idx3-ubyte.gz\n", 30 | "Extracting MNIST_data/t10k-labels-idx1-ubyte.gz\n" 31 | ] 32 | } 33 | ], 34 | "source": [ 35 | "# we use the mnist digits to demonstrate image classifaction using a convolutional neural network\n", 36 | "# use the supplied utility to load MNIST data\n", 37 | "\n", 38 | "from tensorflow.examples.tutorials.mnist import input_data\n", 39 | "mnist = input_data.read_data_sets('MNIST_data', one_hot=True)" 40 | ] 41 | }, 42 | { 43 | "cell_type": "code", 44 | "execution_count": 3, 45 | "metadata": { 46 | "collapsed": false 47 | }, 48 | "outputs": [ 49 | { 50 | "data": { 51 | "text/plain": [ 52 | "55000" 53 | ] 54 | }, 55 | "execution_count": 3, 56 | "metadata": {}, 57 | "output_type": "execute_result" 58 | } 59 | ], 60 | "source": [ 61 | "len(mnist.train.images)" 62 | ] 63 | }, 64 | { 65 | "cell_type": "code", 66 | "execution_count": 4, 67 | "metadata": { 68 | "collapsed": false 69 | }, 70 | "outputs": [ 71 | { 72 | "data": { 73 | "text/plain": [ 74 | "10000" 75 | ] 76 | }, 77 | "execution_count": 4, 78 | "metadata": {}, 79 | "output_type": "execute_result" 80 | } 81 | ], 82 | "source": [ 83 | "len(mnist.test.images)" 84 | ] 85 | }, 86 | { 87 | "cell_type": "code", 88 | "execution_count": 6, 89 | "metadata": { 90 | "collapsed": false 91 | }, 92 | "outputs": [ 93 | { 94 | "data": { 95 | "text/plain": [ 96 | "" 97 | ] 98 | }, 99 | "execution_count": 6, 100 | "metadata": {}, 101 | "output_type": "execute_result" 102 | }, 103 | { 104 | "data": { 105 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAP4AAAD8CAYAAABXXhlaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAADOFJREFUeJzt3X2IVXUex/HPN02wgoxYx2o2XRMfCGLKnhb3jx7ciiUw\nInwqKjdErFZpIXqA8J/+qKXECuqP0rDoyQ1a9Z9WpUBMLHFznTatYFErdbIyGymite/+MUebpvF3\nrnPOufeM3/cLBu8937nnfL36ueee+zvn/szdBSCWk1rdAIDmI/hAQAQfCIjgAwERfCAggg8EVCj4\nZnadme0ws4/N7L6ymgJQLRvoOL6ZnSTpY0lXS9ojabOkme6+o8/vcaIA0CLubv0tL7LHv1TSJ+6+\ny91/lPSqpGkF1gegSYoE/xxJn/a6/1m2DEDN8eEeEFCR4H8u6dxe99uzZQBqrkjwN0saZ2ajzWyY\npJmSVpXTFoAqDR3oA939sJndLWmNel5Alrr79tI6A1CZAQ/nNbwBhvOAlqliOA/AIEXwgYAIPhAQ\nwQcCIvhAQAQfCIjgAwERfCAggg8ERPCBgAg+EBDBBwIi+EBABB8IiOADARF8ICCCDwRE8IGACD4Q\nEMEHAiL4QEAEHwiI4AMBEXwgIIIPBETwgYAIPhAQwQcCIvhAQAQfCIjgAwENLfJgM9sp6aCknyT9\n6O6XltEUgGoVCr56An+Fux8ooxkAzVH0rb6VsA4ATVY0tC5prZltNrO5ZTQEoHpF3+pPcfe9ZvYb\n9bwAbHf3DWU0BqA6hfb47r43+3O/pDck8eEeMAgMOPhmdoqZnZbdPlXSNZI+KKsxANUp8la/TdIb\nZubZel5y9zXltAWgSubu1W6g54UBQAu4u/W3nKE4ICCCDwRE8IGACD4QEMEHAiL4QEAEHwio6Ln6\naLE5c+Yk63nnaXz11VfJ+qRJk5L1jRs3JusbNnDpRh2xxwcCIvhAQAQfCIjgAwERfCAggg8ERPCB\ngAb9OP6sWbOS9QsvvDBZzxsHr7sRI0YUevzhw4eT9WHDhiXr33//fbL+3XffJeudnZ3J+owZM5L1\n/fv3J+voH3t8ICCCDwRE8IGACD4QEMEHAiL4QEAEHwio9t+r/9hjjyXrCxcuTNaHDBlSZPNosbff\nfjtZnz17drLe1dVVZjuDDt+rD+Aogg8ERPCBgAg+EBDBBwIi+EBABB8IKHcc38yWSrpeUpe7X5At\nO0PSa5JGS9opabq7HzzG4wuN4+/evTtZb29vT9a3bduWrOddT161vO+dX7lyZZM6GZipU6cm67fe\nemuyPmbMmELbzxvnnzlzZrJ+ol/PX2Qc/3lJ1/ZZdr+kde4+QdJbkh4o1h6AZsoNvrtvkHSgz+Jp\nkpZnt5dLuqHkvgBUaKDH+CPdvUuS3H2fpJHltQSgamV9uFftCf8ASjXQ4HeZWZskmdkoSV+U1xKA\nqjUafMt+jlgl6fbs9m2S6v3RM4BfyA2+mb0saaOk8Wa228zmSHpE0h/N7CNJV2f3AQwStb8ef/z4\n8cn6+eefn6yvW7cuWe/u7j7untC4sWPHJuurV69O1idNmlRo+/fee2+y/vjjjxdaf91xPT6Aowg+\nEBDBBwIi+EBABB8IiOADARF8IKDaj+PjxHbTTTcl6ytWrCi0/i+//DJZHznyxL6+jHF8AEcRfCAg\ngg8ERPCBgAg+EBDBBwIi+EBABB8IiOADARF8ICCCDwRE8IGACD4QEMEHAiL4QEBDW90ATmzz589P\n1i+++OJKtz98+PBkffLkycn6li1bymynNtjjAwERfCAggg8ERPCBgAg+EBDBBwIi+EBAud+rb2ZL\nJV0vqcvdL8iWLZI0V9IX2a896O5vHuPxfK9+hc4666xk/ZZbbknWFyxYUGY7v3L22Wcn62b9fu17\n03z77bfJ+ogRI5rUSTWKfK/+85Ku7Wf5Yne/KPvpN/QA6ik3+O6+QdKBfkqtfakGMGBFjvHvNrOt\nZvacmZ1eWkcAKjfQ4D8taay7d0jaJ2lxeS0BqNqAgu/u+/3nTwWflXRJeS0BqFqjwTf1OqY3s1G9\najdK+qDMpgBUK/eyXDN7WdIVks40s92SFkm60sw6JP0kaaekeRX2CKBkucF399n9LH6+gl5Cmjp1\narKed7343Llzk/WxY8ced0+RLFu2rNUttARn7gEBEXwgIIIPBETwgYAIPhAQwQcCIvhAQHyvfkHj\nxo1L1p955plk/aqrrkrWq75efdeuXcn6gQP9XZjZuIceeihZ/+GHH5L1p556KlmfMGHCcffU2969\news9frBijw8ERPCBgAg+EBDBBwIi+EBABB8IiOADATGOn+Oee+5J1u+8885k/bzzzkvWDx06lKwf\nPHgwWV+yZEmyvmfPnmR948aNyXreOH/V8v7+ebq7u5P11atXF1r/YMUeHwiI4AMBEXwgIIIPBETw\ngYAIPhAQwQcCYhw/x+WXX56s543Tr1q1KllfvDg97eD69euT9cGuo6MjWR89enSh9edd779jx45C\n6x+s2OMDARF8ICCCDwRE8IGACD4QEMEHAiL4QEC54/hm1i7pBUltkn6S9Ky7P2lmZ0h6TdJoSTsl\nTXf3YhdP19D8+fOT9c7OzmT94YcfLrOdE07evARtbW2F1r9u3bpCjz9RNbLH/5+kv7r7+ZJ+L+ku\nM5so6X5J69x9gqS3JD1QXZsAypQbfHff5+5bs9uHJG2X1C5pmqTl2a8tl3RDVU0CKNdxHeOb2RhJ\nHZI2SWpz9y6p58VB0siymwNQjYaDb2anSXpd0sJsz+99fqXvfQA11VDwzWyoekL/oruvzBZ3mVlb\nVh8l6YtqWgRQtkb3+MskfejuT/RatkrS7dnt2ySt7PsgAPXUyHDeFEk3S+o0s/fV85b+QUmPSlph\nZn+WtEvS9CobBVCe3OC7+zuShhyjPLXcdurn66+/TtYZpy/msssuK/T4b775Jll/8sknC63/RMWZ\ne0BABB8IiOADARF8ICCCDwRE8IGACD4QEN+rj0pt27YtWZ84cWKh9a9ZsyZZ37RpU6H1n6jY4wMB\nEXwgIIIPBETwgYAIPhAQwQcCIvhAQIzjo1JjxoxJ1ocOTf8XPHgwPVXDkiVLjrcliD0+EBLBBwIi\n+EBABB8IiOADARF8ICCCDwTEOD4KmTVrVrI+fPjwZL27uztZnzdvXrLO9fYDwx4fCIjgAwERfCAg\ngg8ERPCBgAg+EFBu8M2s3czeMrP/mFmnmf0lW77IzD4zs39lP9dV3y6AMpi7p3/BbJSkUe6+1cxO\nk7RF0jRJMyR1u/vinMenN4BaO/nkk5P1d999N1nP+978V155JVm/4447knWkubv1tzz3BB533ydp\nX3b7kJltl3ROVu53pQDq7biO8c1sjKQOSUde5u82s61m9pyZnV5ybwAq0nDws7f5r0ta6O6HJD0t\naay7d6jnHUHyLT+A+mgo+GY2VD2hf9HdV0qSu+/3nz8geFbSJdW0CKBsje7xl0n60N2fOLIg+9Dv\niBslfVBmYwCqk/vhnplNkXSzpE4ze1+SS3pQ0mwz65D0k6SdktKXUQGojUY+1X9H0pB+Sm+W3w6A\nZuB6fCTlneeRNw6/devWZH3t2rXH3ROK45RdICCCDwRE8IGACD4QEMEHAiL4QEAEHwgo93r8whvg\nenygZY51PT57fCAggg8ERPCBgAg+EBDBBwIi+EBABB8IiOADAVV+Ag+A+mGPDwRE8IGAmhZ8M7vO\nzHaY2cdmdl+zttsoM9tpZv82s/fN7L0a9LPUzLrMbFuvZWeY2Roz+8jM/tnK2YuO0V9tJlLtZ7LX\nBdnyWjyHrZ6MtinH+GZ2kqSPJV0taY+kzZJmuvuOyjfeIDP7r6TJ7n6g1b1Ikpn9QdIhSS+4+wXZ\nskclfeXuf8tePM9w9/tr1N8iNTCRajMkJnudoxo8h0Unoy2qWXv8SyV94u673P1HSa+q5y9ZJ6Ya\nHfq4+wZJfV+Epklant1eLumGpjbVyzH6k2oykaq773P3rdntQ5K2S2pXTZ7DY/TXtMlom/Uf/RxJ\nn/a6/5l+/kvWhUtaa2abzWxuq5s5hpHu3iUdncV4ZIv76U/tJlLtNdnrJkltdXsOWzEZbW32cDUw\nxd0vkvQnSXdlb2Xrrm5jsbWbSLWfyV77PmctfQ5bNRlts4L/uaRze91vz5bVhrvvzf7cL+kN9Rye\n1E2XmbVJR48Rv2hxP79Qt4lU+5vsVTV6Dls5GW2zgr9Z0jgzG21mwyTNlLSqSdvOZWanZK+8MrNT\nJV2jekwCavrl8d4qSbdnt2+TtLLvA5rsF/3VcCLVX032qno9hy2bjLZpZ+5lwxJPqOfFZqm7P9KU\nDTfAzH6nnr28q2dasZda3Z+ZvSzpCklnSuqStEjSPyT9XdJvJe2SNN3dv6lRf1eq51j16ESqR46n\nW9DfFEnrJXWq59/1yGSv70laoRY/h4n+ZqsJzyGn7AIB8eEeEBDBBwIi+EBABB8IiOADARF8ICCC\nDwRE8IGA/g8LkpS7I5eATAAAAABJRU5ErkJggg==\n", 106 | "text/plain": [ 107 | "" 108 | ] 109 | }, 110 | "metadata": {}, 111 | "output_type": "display_data" 112 | } 113 | ], 114 | "source": [ 115 | "from skimage import io\n", 116 | "io.imshow(np.reshape(mnist.train.images[0],(28,28)))" 117 | ] 118 | }, 119 | { 120 | "cell_type": "code", 121 | "execution_count": 7, 122 | "metadata": { 123 | "collapsed": false 124 | }, 125 | "outputs": [ 126 | { 127 | "data": { 128 | "text/plain": [ 129 | "array([ 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.])" 130 | ] 131 | }, 132 | "execution_count": 7, 133 | "metadata": {}, 134 | "output_type": "execute_result" 135 | } 136 | ], 137 | "source": [ 138 | "mnist.train.labels[0]" 139 | ] 140 | }, 141 | { 142 | "cell_type": "code", 143 | "execution_count": 35, 144 | "metadata": { 145 | "collapsed": false, 146 | "scrolled": true 147 | }, 148 | "outputs": [], 149 | "source": [ 150 | "def weight_variable(dimensions,stddev):\n", 151 | " return tf.Variable(tf.truncated_normal(dimensions, stddev=stddev))\n", 152 | "\n", 153 | "def bias_variable(dimensions,constant):\n", 154 | " return tf.Variable(tf.constant(constant, shape=dimensions))\n", 155 | "\n", 156 | "def two_dimensional_convolutional_layer(x, W, strides, padding):\n", 157 | " return tf.nn.conv2d(x, W, strides=strides, padding=padding)\n", 158 | "\n", 159 | "def max_pooling(x,strides,ksize,padding):\n", 160 | " return tf.nn.max_pool(x, ksize=ksize,strides=strides, padding=padding)\n", 161 | "\n", 162 | "def generate_network(weight_variables,\\\n", 163 | " bias_variables,\\\n", 164 | " relu_layers,\\\n", 165 | " pooling_layers,\\\n", 166 | " fully_connected_layers,\\\n", 167 | " inputs,\\\n", 168 | " conv_strides,\\\n", 169 | " pool_stries,\\\n", 170 | " ksize,\\\n", 171 | " output_channels,\\\n", 172 | " conv_field_sizes,\\\n", 173 | " conv_field_depths,\\\n", 174 | " sd_weights\\\n", 175 | " ,bias_mean,\\\n", 176 | " padding,\\\n", 177 | " conv_layers,\\\n", 178 | " fc_layers,\\\n", 179 | " fc_shape,\\\n", 180 | " keep_prob,\\\n", 181 | " class_num,\\\n", 182 | " dropouts):\n", 183 | " \n", 184 | " # add convolutional layers\n", 185 | " for k in range(conv_layers):\n", 186 | " weight_variables.append(weight_variable([conv_field_sizes[k], conv_field_sizes[k], conv_field_depths[k],\\\n", 187 | " output_channels[k]],sd_weights))\n", 188 | " bias_variables.append(bias_variable([output_channels[k]],bias_mean))\n", 189 | " relu_layers.append(tf.nn.relu(two_dimensional_convolutional_layer(inputs[k],weight_variables[k],\\\n", 190 | " conv_strides,padding) + bias_variables[k]))\n", 191 | " pooling_layers.append(max_pooling(relu_layers[k],pool_strides,ksize,padding))\n", 192 | " inputs.append(pooling_layers[k])\n", 193 | " \n", 194 | " # finally, add fully connected layers at end with dropout\n", 195 | " for r in range(fc_layers):\n", 196 | " weight_variables.append(weight_variable(fc_shape,sd_weights))\n", 197 | " bias_variables.append(bias_variable([fc_shape[1]],bias_mean))\n", 198 | " pooling_layers.append(tf.reshape(pooling_layers[-1],[-1,fc_shape[0]]))\n", 199 | " fully_connected_layers.append(tf.nn.relu(tf.matmul(pooling_layers[-1], weight_variables[-1]) + bias_variables[-1]))\n", 200 | " dropouts.append(tf.nn.dropout(fully_connected_layers[-1], keep_prob))\n", 201 | " \n", 202 | " # output layer\n", 203 | " weight_variables.append(weight_variable([fc_shape[1],class_num],sd_weights))\n", 204 | " bias_variables.append(bias_variable([class_num],bias_mean))\n", 205 | " return tf.nn.softmax(tf.matmul(dropouts[-1],weight_variables[-1])+bias_variables[-1])" 206 | ] 207 | }, 208 | { 209 | "cell_type": "code", 210 | "execution_count": 53, 211 | "metadata": { 212 | "collapsed": false 213 | }, 214 | "outputs": [], 215 | "source": [ 216 | "X = tf.placeholder(\"float\", shape=[None, 784])\n", 217 | "observed = tf.placeholder(\"float\", shape=[None, 10])\n", 218 | "images = tf.reshape(X, [-1,28,28,1])\n", 219 | "\n", 220 | "# shape variables\n", 221 | "sd_weights = 0.1\n", 222 | "bias_mean = 0.1\n", 223 | "padding = 'SAME'\n", 224 | "conv_strides = [1,1,1,1]\n", 225 | "pool_strides = [1,2,2,1]\n", 226 | "ksize = [1,2,2,1]\n", 227 | "output_channels = [32,64]\n", 228 | "conv_field_sizes = [5,5]\n", 229 | "conv_field_depths = [1,32]\n", 230 | "fc_shape = [7*7*64,1024]\n", 231 | "keep_prob = tf.placeholder(\"float\")\n", 232 | "class_num = 10\n", 233 | "conv_layers = 2\n", 234 | "fc_layers = 1\n", 235 | "\n", 236 | "# layers variables\n", 237 | "weight_variables = []\n", 238 | "bias_variables = []\n", 239 | "relu_layers = []\n", 240 | "pooling_layers = []\n", 241 | "inputs = [images]\n", 242 | "fully_connected_layers = []\n", 243 | "dropouts = []\n", 244 | "\n", 245 | "prediction = generate_network(weight_variables,\\\n", 246 | " bias_variables,\\\n", 247 | " relu_layers,\\\n", 248 | " pooling_layers,\\\n", 249 | " fully_connected_layers,\\\n", 250 | " inputs,\\\n", 251 | " conv_strides,\\\n", 252 | " pool_strides,\\\n", 253 | " ksize,\\\n", 254 | " output_channels,\\\n", 255 | " conv_field_sizes,\\\n", 256 | " conv_field_depths,\\\n", 257 | " sd_weights\\\n", 258 | " ,bias_mean,\\\n", 259 | " padding,\\\n", 260 | " conv_layers,\\\n", 261 | " fc_layers,\\\n", 262 | " fc_shape,\\\n", 263 | " keep_prob,\\\n", 264 | " class_num,\\\n", 265 | " dropouts)" 266 | ] 267 | }, 268 | { 269 | "cell_type": "code", 270 | "execution_count": 54, 271 | "metadata": { 272 | "collapsed": false 273 | }, 274 | "outputs": [ 275 | { 276 | "name": "stdout", 277 | "output_type": "stream", 278 | "text": [ 279 | "step 0, training accuracy 0.04\n", 280 | "step 100, training accuracy 0.06\n", 281 | "step 200, training accuracy 0.1\n", 282 | "step 300, training accuracy 0.16\n", 283 | "step 400, training accuracy 0.16\n", 284 | "step 500, training accuracy 0.1\n", 285 | "step 600, training accuracy 0.1\n", 286 | "step 700, training accuracy 0.12\n", 287 | "step 800, training accuracy 0.16\n", 288 | "step 900, training accuracy 0.06\n", 289 | "step 1000, training accuracy 0.14\n", 290 | "step 1100, training accuracy 0.06\n", 291 | "step 1200, training accuracy 0.14\n", 292 | "step 1300, training accuracy 0.1\n", 293 | "step 1400, training accuracy 0.08\n", 294 | "step 1500, training accuracy 0.18\n", 295 | "step 1600, training accuracy 0.1\n", 296 | "step 1700, training accuracy 0.18\n", 297 | "step 1800, training accuracy 0.06\n", 298 | "step 1900, training accuracy 0.08\n", 299 | "step 2000, training accuracy 0.16\n", 300 | "step 2100, training accuracy 0.24\n", 301 | "step 2200, training accuracy 0.1\n", 302 | "step 2300, training accuracy 0.18\n", 303 | "step 2400, training accuracy 0.12\n", 304 | "step 2500, training accuracy 0.06\n", 305 | "step 2600, training accuracy 0.1\n", 306 | "step 2700, training accuracy 0.08\n", 307 | "step 2800, training accuracy 0.18\n", 308 | "step 2900, training accuracy 0.1\n", 309 | "step 3000, training accuracy 0.04\n", 310 | "step 3100, training accuracy 0.1\n", 311 | "step 3200, training accuracy 0.12\n", 312 | "step 3300, training accuracy 0\n", 313 | "step 3400, training accuracy 0.18\n", 314 | "step 3500, training accuracy 0.12\n", 315 | "step 3600, training accuracy 0.08\n", 316 | "step 3700, training accuracy 0.18\n", 317 | "step 3800, training accuracy 0.1\n", 318 | "step 3900, training accuracy 0.06\n", 319 | "step 4000, training accuracy 0.02\n", 320 | "step 4100, training accuracy 0.14\n", 321 | "step 4200, training accuracy 0.2\n", 322 | "step 4300, training accuracy 0.16\n", 323 | "step 4400, training accuracy 0.06\n", 324 | "step 4500, training accuracy 0.14\n", 325 | "step 4600, training accuracy 0.06\n", 326 | "step 4700, training accuracy 0.12\n", 327 | "step 4800, training accuracy 0.14\n", 328 | "step 4900, training accuracy 0.16\n", 329 | "step 5000, training accuracy 0.06\n", 330 | "step 5100, training accuracy 0.08\n", 331 | "step 5200, training accuracy 0.12\n", 332 | "step 5300, training accuracy 0.18\n", 333 | "step 5400, training accuracy 0.12\n", 334 | "step 5500, training accuracy 0.22\n", 335 | "step 5600, training accuracy 0.1\n", 336 | "step 5700, training accuracy 0.12\n", 337 | "step 5800, training accuracy 0.02\n", 338 | "step 5900, training accuracy 0.12\n", 339 | "step 6000, training accuracy 0.14\n", 340 | "step 6100, training accuracy 0.18\n", 341 | "step 6200, training accuracy 0.18\n", 342 | "step 6300, training accuracy 0.12\n", 343 | "step 6400, training accuracy 0.14\n", 344 | "step 6500, training accuracy 0.02\n", 345 | "step 6600, training accuracy 0.14\n", 346 | "step 6700, training accuracy 0.12\n", 347 | "step 6800, training accuracy 0.22\n", 348 | "step 6900, training accuracy 0.14\n", 349 | "step 7000, training accuracy 0.12\n", 350 | "step 7100, training accuracy 0.12\n", 351 | "step 7200, training accuracy 0.12\n", 352 | "step 7300, training accuracy 0.12\n", 353 | "step 7400, training accuracy 0.06\n", 354 | "step 7500, training accuracy 0.16\n", 355 | "step 7600, training accuracy 0.16\n", 356 | "step 7700, training accuracy 0.04\n", 357 | "step 7800, training accuracy 0.08\n", 358 | "step 7900, training accuracy 0.22\n", 359 | "step 8000, training accuracy 0.06\n", 360 | "step 8100, training accuracy 0.14\n", 361 | "step 8200, training accuracy 0.08\n", 362 | "step 8300, training accuracy 0.14\n", 363 | "step 8400, training accuracy 0.08\n", 364 | "step 8500, training accuracy 0.06\n" 365 | ] 366 | }, 367 | { 368 | "ename": "KeyboardInterrupt", 369 | "evalue": "", 370 | "output_type": "error", 371 | "traceback": [ 372 | "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", 373 | "\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", 374 | "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[1;32m 10\u001b[0m X: batch[0], observed: batch[1], keep_prob: 1.0})\n\u001b[1;32m 11\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"step %d, training accuracy %g\"\u001b[0m\u001b[0;34m%\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtrain_accuracy\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 12\u001b[0;31m \u001b[0mtrain_step\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mfeed_dict\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m{\u001b[0m\u001b[0mX\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mbatch\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mobserved\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mbatch\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mkeep_prob\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0;36m0.5\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 13\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 14\u001b[0m print(\"test accuracy %g\"%accuracy.eval(feed_dict={\n", 375 | "\u001b[0;32m/usr/local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, feed_dict, session)\u001b[0m\n\u001b[1;32m 1337\u001b[0m \u001b[0mnone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mthe\u001b[0m \u001b[0mdefault\u001b[0m \u001b[0msession\u001b[0m \u001b[0mwill\u001b[0m \u001b[0mbe\u001b[0m \u001b[0mused\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1338\u001b[0m \"\"\"\n\u001b[0;32m-> 1339\u001b[0;31m \u001b[0m_run_using_default_session\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgraph\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msession\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 1340\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 1341\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", 376 | "\u001b[0;32m/usr/local/lib/python3.5/site-packages/tensorflow/python/framework/ops.py\u001b[0m in \u001b[0;36m_run_using_default_session\u001b[0;34m(operation, feed_dict, graph, session)\u001b[0m\n\u001b[1;32m 2959\u001b[0m \u001b[0;34m\"the operation's graph is different from the session's \"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2960\u001b[0m \"graph.\")\n\u001b[0;32m-> 2961\u001b[0;31m \u001b[0msession\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0moperation\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfeed_dict\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2962\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2963\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", 377 | "\u001b[0;32m/usr/local/lib/python3.5/site-packages/tensorflow/python/client/session.py\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, fetches, feed_dict)\u001b[0m\n\u001b[1;32m 371\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 372\u001b[0m \u001b[0;31m# Run request and get response.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 373\u001b[0;31m \u001b[0mresults\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_do_run\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtarget_list\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0munique_fetch_targets\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mfeed_dict_string\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 374\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 375\u001b[0m \u001b[0;31m# User may have fetched the same tensor multiple times, but we\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 378 | "\u001b[0;32m/usr/local/lib/python3.5/site-packages/tensorflow/python/client/session.py\u001b[0m in \u001b[0;36m_do_run\u001b[0;34m(self, target_list, fetch_list, feed_dict)\u001b[0m\n\u001b[1;32m 431\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 432\u001b[0m return tf_session.TF_Run(self._session, feed_dict, fetch_list,\n\u001b[0;32m--> 433\u001b[0;31m target_list)\n\u001b[0m\u001b[1;32m 434\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 435\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mtf_session\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mStatusNotOK\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", 379 | "\u001b[0;31mKeyboardInterrupt\u001b[0m: " 380 | ] 381 | } 382 | ], 383 | "source": [ 384 | "my_session = tf.InteractiveSession()\n", 385 | "squared_error = tf.reduce_sum(tf.pow(tf.reduce_sum(tf.sub(observed,prediction)),[2]))\n", 386 | "train_step = tf.train.GradientDescentOptimizer(0.01).minimize(squared_error)\n", 387 | "correct_prediction = tf.equal(tf.argmax(prediction,1), tf.argmax(observed,1))\n", 388 | "accuracy = tf.reduce_mean(tf.cast(correct_prediction, \"float\"))\n", 389 | "my_session.run(tf.initialize_all_variables())\n", 390 | "\n", 391 | "for i in range(20000):\n", 392 | " batch = mnist.train.next_batch(50)\n", 393 | " if i%1000 == 0:\n", 394 | " train_accuracy = accuracy.eval(feed_dict={\n", 395 | " X: batch[0], observed: batch[1], keep_prob: 1.0})\n", 396 | " print(\"step %d, training accuracy %g\"%(i, train_accuracy))\n", 397 | " train_step.run(feed_dict={X: batch[0], observed: batch[1], keep_prob: 0.5})\n", 398 | "\n", 399 | "print(\"test accuracy %g\"%accuracy.eval(feed_dict={\n", 400 | " X: mnist.test.images, observed: mnist.test.labels, keep_prob: 1.0}))" 401 | ] 402 | }, 403 | { 404 | "cell_type": "code", 405 | "execution_count": null, 406 | "metadata": { 407 | "collapsed": true 408 | }, 409 | "outputs": [], 410 | "source": [] 411 | } 412 | ], 413 | "metadata": { 414 | "kernelspec": { 415 | "display_name": "Python 3", 416 | "language": "python", 417 | "name": "python3" 418 | }, 419 | "language_info": { 420 | "codemirror_mode": { 421 | "name": "ipython", 422 | "version": 3 423 | }, 424 | "file_extension": ".py", 425 | "mimetype": "text/x-python", 426 | "name": "python", 427 | "nbconvert_exporter": "python", 428 | "pygments_lexer": "ipython3", 429 | "version": "3.5.1" 430 | } 431 | }, 432 | "nbformat": 4, 433 | "nbformat_minor": 0 434 | } 435 | -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_07_code/MNIST_data/t10k-images-idx3-ubyte.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Advanced-Predictive-Analytics/eda343c48e58b613c28a21a35155f213f4b1771a/Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_07_code/MNIST_data/t10k-images-idx3-ubyte.gz -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_07_code/MNIST_data/t10k-labels-idx1-ubyte.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Advanced-Predictive-Analytics/eda343c48e58b613c28a21a35155f213f4b1771a/Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_07_code/MNIST_data/t10k-labels-idx1-ubyte.gz -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_07_code/MNIST_data/train-images-idx3-ubyte.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Advanced-Predictive-Analytics/eda343c48e58b613c28a21a35155f213f4b1771a/Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_07_code/MNIST_data/train-images-idx3-ubyte.gz -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_07_code/MNIST_data/train-labels-idx1-ubyte.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Advanced-Predictive-Analytics/eda343c48e58b613c28a21a35155f213f4b1771a/Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_07_code/MNIST_data/train-labels-idx1-ubyte.gz -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_08_code/B04881_chapter_08_code_01.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 8, 6 | "metadata": { 7 | "collapsed": false, 8 | "scrolled": true 9 | }, 10 | "outputs": [ 11 | { 12 | "name": "stderr", 13 | "output_type": "stream", 14 | "text": [ 15 | "[09/Feb/2016:01:09:26] ENGINE Bus STARTING\n", 16 | "INFO:cherrypy.error:[09/Feb/2016:01:09:26] ENGINE Bus STARTING\n", 17 | "[09/Feb/2016:01:09:26] ENGINE Started monitor thread '_TimeoutMonitor'.\n", 18 | "INFO:cherrypy.error:[09/Feb/2016:01:09:26] ENGINE Started monitor thread '_TimeoutMonitor'.\n", 19 | "[09/Feb/2016:01:09:26] ENGINE Started monitor thread 'Autoreloader'.\n", 20 | "INFO:cherrypy.error:[09/Feb/2016:01:09:26] ENGINE Started monitor thread 'Autoreloader'.\n", 21 | "[09/Feb/2016:01:09:26] ENGINE Serving on http://0.0.0.0:5432\n", 22 | "INFO:cherrypy.error:[09/Feb/2016:01:09:26] ENGINE Serving on http://0.0.0.0:5432\n", 23 | "[09/Feb/2016:01:09:26] ENGINE Bus STARTED\n", 24 | "INFO:cherrypy.error:[09/Feb/2016:01:09:26] ENGINE Bus STARTED\n", 25 | "[09/Feb/2016:01:13:38] ENGINE Keyboard Interrupt: shutting down bus\n", 26 | "INFO:cherrypy.error:[09/Feb/2016:01:13:38] ENGINE Keyboard Interrupt: shutting down bus\n", 27 | "[09/Feb/2016:01:13:38] ENGINE Bus STOPPING\n", 28 | "INFO:cherrypy.error:[09/Feb/2016:01:13:38] ENGINE Bus STOPPING\n", 29 | "[09/Feb/2016:01:13:38] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('0.0.0.0', 5432)) shut down\n", 30 | "INFO:cherrypy.error:[09/Feb/2016:01:13:38] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('0.0.0.0', 5432)) shut down\n", 31 | "[09/Feb/2016:01:13:38] ENGINE Stopped thread 'Autoreloader'.\n", 32 | "INFO:cherrypy.error:[09/Feb/2016:01:13:38] ENGINE Stopped thread 'Autoreloader'.\n", 33 | "[09/Feb/2016:01:13:38] ENGINE Stopped thread '_TimeoutMonitor'.\n", 34 | "INFO:cherrypy.error:[09/Feb/2016:01:13:38] ENGINE Stopped thread '_TimeoutMonitor'.\n", 35 | "[09/Feb/2016:01:13:38] ENGINE Bus STOPPED\n", 36 | "INFO:cherrypy.error:[09/Feb/2016:01:13:38] ENGINE Bus STOPPED\n", 37 | "[09/Feb/2016:01:13:38] ENGINE Bus EXITING\n", 38 | "INFO:cherrypy.error:[09/Feb/2016:01:13:38] ENGINE Bus EXITING\n", 39 | "[09/Feb/2016:01:13:38] ENGINE Bus EXITED\n", 40 | "INFO:cherrypy.error:[09/Feb/2016:01:13:38] ENGINE Bus EXITED\n", 41 | "[09/Feb/2016:01:13:38] ENGINE Waiting for child threads to terminate...\n", 42 | "INFO:cherrypy.error:[09/Feb/2016:01:13:38] ENGINE Waiting for child threads to terminate...\n", 43 | "[09/Feb/2016:01:13:38] ENGINE Waiting for thread HTTPServer Thread-7.\n", 44 | "INFO:cherrypy.error:[09/Feb/2016:01:13:38] ENGINE Waiting for thread HTTPServer Thread-7.\n" 45 | ] 46 | } 47 | ], 48 | "source": [ 49 | "import cherrypy\n", 50 | "from pyspark import SparkConf, SparkContext\n", 51 | "from modelservice import prediction_service\n", 52 | "\n", 53 | "def start_spark_context():\n", 54 | " conf = SparkConf().setAppName(\"prediction-service\")\n", 55 | " sc = SparkContext(conf=conf, pyFiles=['modelfactory.py', 'modelservice.py'])\n", 56 | "\n", 57 | " return sc\n", 58 | "\n", 59 | "def run_server(app):\n", 60 | "\n", 61 | " cherrypy.config.update({\n", 62 | " 'engine.autoreload.on': True,\n", 63 | " 'log.screen': True,\n", 64 | " 'server.socket_port': 5432,\n", 65 | " 'server.socket_host': '0.0.0.0'\n", 66 | " })\n", 67 | "\n", 68 | " cherrypy.engine.start()\n", 69 | " cherrypy.engine.block()\n", 70 | " \n", 71 | "if __name__ == \"__main__\":\n", 72 | "\n", 73 | " sc = start_spark_context()\n", 74 | " parameters = json.loads(open('parameters.json').readline())\n", 75 | " service = prediction_service('LogisticRegression',parameters,sc)\n", 76 | "\n", 77 | " run_server(service)" 78 | ] 79 | }, 80 | { 81 | "cell_type": "code", 82 | "execution_count": null, 83 | "metadata": { 84 | "collapsed": true 85 | }, 86 | "outputs": [], 87 | "source": [] 88 | } 89 | ], 90 | "metadata": { 91 | "kernelspec": { 92 | "display_name": "Python 3", 93 | "language": "python", 94 | "name": "python3" 95 | }, 96 | "language_info": { 97 | "codemirror_mode": { 98 | "name": "ipython", 99 | "version": 3 100 | }, 101 | "file_extension": ".py", 102 | "mimetype": "text/x-python", 103 | "name": "python", 104 | "nbconvert_exporter": "python", 105 | "pygments_lexer": "ipython3", 106 | "version": "3.5.1" 107 | } 108 | }, 109 | "nbformat": 4, 110 | "nbformat_minor": 0 111 | } 112 | -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_08_code/B04881_chapter_08_code_02.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 47, 6 | "metadata": { 7 | "collapsed": false 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "import requests\n", 12 | "import json" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 39, 18 | "metadata": { 19 | "collapsed": true 20 | }, 21 | "outputs": [], 22 | "source": [ 23 | "parameters = json.dumps({\"schema\": {\"delimiter\": \",\", \"features\": [{\"values\": {\"1st\": 0, \"2nd\": 1, \"3rd\": 2, \"Crew\": 3}, \"name\": \"Class\", \"pos\": 1}, {\"values\": {\"Female\": 1, \"Male\": 0}, \"name\": \"Sex\", \"pos\": 2}, {\"values\": {\"Child\": 0, \"Adult\": 1}, \"name\": \"Age\", \"pos\": 3}], \"label\": {\"values\": {\"No\": 0.0, \"Yes\": 1.0}, \"pos\": 4}}, \"numFeatures\": 3, \"iterations\": 10, \"numClasses\": 2, \"header\": true})" 24 | ] 25 | }, 26 | { 27 | "cell_type": "code", 28 | "execution_count": 66, 29 | "metadata": { 30 | "collapsed": false 31 | }, 32 | "outputs": [], 33 | "source": [ 34 | "r = requests.get(\"http://0.0.0.0:5000/train/Titanic.csv/{0}\".format(parameters))" 35 | ] 36 | } 37 | ], 38 | "metadata": { 39 | "kernelspec": { 40 | "display_name": "Python 3", 41 | "language": "python", 42 | "name": "python3" 43 | }, 44 | "language_info": { 45 | "codemirror_mode": { 46 | "name": "ipython", 47 | "version": 3 48 | }, 49 | "file_extension": ".py", 50 | "mimetype": "text/x-python", 51 | "name": "python", 52 | "nbconvert_exporter": "python", 53 | "pygments_lexer": "ipython3", 54 | "version": "3.5.1" 55 | } 56 | }, 57 | "nbformat": 4, 58 | "nbformat_minor": 0 59 | } 60 | -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_08_code/LogisticRegression.py: -------------------------------------------------------------------------------- 1 | from pyspark.mllib.classification import LogisticRegressionWithLBFGS 2 | import json 3 | from dataparser import DataParser 4 | 5 | class LogisticRegression: 6 | 7 | def __init__(self,parameters,sc): 8 | 9 | parameters = json.loads(parameters) 10 | schema = parameters.get('schema',None) 11 | header = parameters.get('header',False) 12 | self._parser = DataParser(schema,header) 13 | self._sc = sc 14 | 15 | def predict(self,input_data): 16 | return self._model.predict(input_data) 17 | 18 | def train(self,input_data,parameters): 19 | iterations = parameters.get('iterations',None) 20 | weights = parameters.get('weights',None) 21 | intercept = parameters.get('intercept',None) 22 | numFeatures = parameters.get('numFeatures',None) 23 | numClasses = parameters.get('numClasses',None) 24 | data = self._sc.parallelize(self._parser.parse(input_data)) 25 | self._model = LogisticRegressionWithLBFGS.train(data,\ 26 | iterations=iterations,\ 27 | numClasses=numClasses) -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_08_code/Titanic.csv: -------------------------------------------------------------------------------- 1 | "","Class","Sex","Age","Survived","Freq" 2 | "1","1st","Male","Child","No",0 3 | "2","2nd","Male","Child","No",0 4 | "3","3rd","Male","Child","No",35 5 | "4","Crew","Male","Child","No",0 6 | "5","1st","Female","Child","No",0 7 | "6","2nd","Female","Child","No",0 8 | "7","3rd","Female","Child","No",17 9 | "8","Crew","Female","Child","No",0 10 | "9","1st","Male","Adult","No",118 11 | "10","2nd","Male","Adult","No",154 12 | "11","3rd","Male","Adult","No",387 13 | "12","Crew","Male","Adult","No",670 14 | "13","1st","Female","Adult","No",4 15 | "14","2nd","Female","Adult","No",13 16 | "15","3rd","Female","Adult","No",89 17 | "16","Crew","Female","Adult","No",3 18 | "17","1st","Male","Child","Yes",5 19 | "18","2nd","Male","Child","Yes",11 20 | "19","3rd","Male","Child","Yes",13 21 | "20","Crew","Male","Child","Yes",0 22 | "21","1st","Female","Child","Yes",1 23 | "22","2nd","Female","Child","Yes",13 24 | "23","3rd","Female","Child","Yes",14 25 | "24","Crew","Female","Child","Yes",0 26 | "25","1st","Male","Adult","Yes",57 27 | "26","2nd","Male","Adult","Yes",14 28 | "27","3rd","Male","Adult","Yes",75 29 | "28","Crew","Male","Adult","Yes",192 30 | "29","1st","Female","Adult","Yes",140 31 | "30","2nd","Female","Adult","Yes",80 32 | "31","3rd","Female","Adult","Yes",76 33 | "32","Crew","Female","Adult","Yes",20 34 | -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_08_code/dataparser.py: -------------------------------------------------------------------------------- 1 | from pyspark.mllib.regression import LabeledPoint 2 | 3 | class DataParser: 4 | 5 | def __init__(self,schema_dict,header=False): 6 | 7 | ''' 8 | schema takes the form { 9 | label: dict with position, values (also a dict with key -> position mapping) 10 | delimiter: delimiter 11 | features: array of dicts: 12 | dict with position, values (also a dict with key -> position mapping) 13 | } 14 | schema = { 15 | 'delimiter': ',', 16 | 'label': { 'pos': 3, 'values': { 'Yes': 1.0, 'No': 0.0 } }, 17 | 'features': [ 18 | { 'name': 'Class', 'pos': 0, 'values': {'1st':0, '2nd':1, '3rd':2, 'Crew':3 } }, 19 | { 'name': 'Sex', 'pos': 1, 'values': {'Male':0, 'Female':1} }, 20 | { 'name': 'Age', 'pos': 2, 'values': {'Child':0, 'Adult':1} } 21 | ] 22 | } 23 | 24 | 25 | ''' 26 | 27 | 28 | 29 | self.schema_dict = schema_dict 30 | self.header = header 31 | 32 | def parse_line(self,input_line): 33 | 34 | try: 35 | input_array = input_line.strip().replace('\"','').split(self.schema_dict['delimiter']) 36 | 37 | if self.schema_dict['label'].get('values',None) is not None: 38 | label = self.schema_dict['label']['values'][input_array[self.schema_dict['label']['pos']]] 39 | else: 40 | label = input_array[self.schema_dict['label']['pos']] # just get at this position 41 | 42 | features = [] 43 | 44 | for f in self.schema_dict['features']: 45 | # is categorical? 46 | if f.get('values',None) is not None: 47 | cat_feature = [ 0 ] * len(f['values'].keys()) 48 | if input_array[f['pos']]!=len(f['values'].keys()): # 1 hot encoding 49 | cat_feature[f['values'][input_array[f['pos']]]] = 1 50 | features += cat_feature # numerical 51 | else: 52 | features += input_array[f['pos']] 53 | 54 | return LabeledPoint(label,features) 55 | 56 | except: 57 | print('failed to parse line: '.format(input_line)) 58 | pass 59 | 60 | def parse(self,input_data): 61 | 62 | inputs = open(input_data) 63 | 64 | if self.header: 65 | inputs.readline() 66 | 67 | return [ self.parse_line(l) for l in inputs.readlines() ] 68 | 69 | inputs.close() 70 | 71 | 72 | -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_08_code/model_server.py: -------------------------------------------------------------------------------- 1 | # dependencies 2 | import cherrypy 3 | from pyspark import SparkConf, SparkContext 4 | from modelservice import prediction_service 5 | import json 6 | 7 | def start_spark_context(): 8 | conf = SparkConf().setAppName("prediction-service").set("spark.driver.allowMultipleContexts",True) 9 | sc = SparkContext(conf=conf, pyFiles=['modelfactory.py', 'modelservice.py']) 10 | 11 | return sc 12 | 13 | def run_server(app): 14 | 15 | import paste 16 | from paste.translogger import TransLogger 17 | 18 | app_ = TransLogger(app) 19 | 20 | cherrypy.tree.graft(app_, '/') 21 | 22 | cherrypy.config.update({ 23 | 'engine.autoreload.on': True, 24 | 'log.screen': True, 25 | 'server.socket_port': 5000, 26 | 'server.socket_host': '0.0.0.0' 27 | }) 28 | 29 | cherrypy.engine.start() 30 | cherrypy.engine.block() 31 | 32 | if __name__ == "__main__": 33 | 34 | sc = start_spark_context() 35 | parameters = json.loads(open('parameters.json').readline()) 36 | service = prediction_service('LogisticRegression',parameters,sc) 37 | 38 | run_server(service) -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_08_code/modelfactory.py: -------------------------------------------------------------------------------- 1 | import importlib 2 | 3 | class ModelFactory: 4 | 5 | def train(self,input_data,parameters): 6 | ''' 7 | trains a model based on input data 8 | ''' 9 | self.model.train(input_data,parameters) 10 | 11 | def predict(self,data): 12 | return self.model.predict(data) 13 | 14 | def __init__(self,model_name,model_parameters,sc): 15 | ''' 16 | loads a model class and initializes sparkContext 17 | ''' 18 | module = importlib.import_module(model_name) 19 | model_class = getattr(module, model_name) 20 | self.model = model_class(model_parameters,sc) 21 | 22 | -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_08_code/modelservice.py: -------------------------------------------------------------------------------- 1 | from flask import Blueprint 2 | main = Blueprint('main', __name__) 3 | 4 | import json 5 | from modelfactory import ModelFactory 6 | 7 | from flask import Flask, request 8 | 9 | import logging 10 | logging.basicConfig(level=logging.INFO) 11 | logger = logging.getLogger(__name__) 12 | 13 | @main.route("/train/",methods=["POST"]) 14 | def train(input_data): 15 | parsed_parameters = request.json 16 | model.train(input_data,parsed_parameters) 17 | return json.dumps("done training") 18 | 19 | @main.route("/predict/") 20 | def predict(input_data): 21 | parsed_data = [float(e) for e in input_data.split(',')] 22 | score = model.predict(parsed_data) 23 | return json.dumps(score) 24 | 25 | def prediction_service(model_name,model_parameters,spark_context): 26 | global model 27 | 28 | model = ModelFactory(model_name,model_parameters,spark_context) 29 | service = Flask(__name__) 30 | service.register_blueprint(main) 31 | return service 32 | -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/B04881_08_code/parameters.json: -------------------------------------------------------------------------------- 1 | "{\"schema\": {\"delimiter\": \",\", \"features\": [{\"values\": {\"1st\": 0, \"2nd\": 1, \"3rd\": 2, \"Crew\": 3}, \"name\": \"Class\", \"pos\": 1}, {\"values\": {\"Female\": 1, \"Male\": 0}, \"name\": \"Sex\", \"pos\": 2}, {\"values\": {\"Child\": 0, \"Adult\": 1}, \"name\": \"Age\", \"pos\": 3}], \"label\": {\"values\": {\"No\": 0.0, \"Yes\": 1.0}, \"pos\": 4}}, \"numFeatures\": 3, \"iterations\": 10, \"numClasses\": 2, \"header\": true}" -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/README.txt: -------------------------------------------------------------------------------- 1 | There are no code files available for chapter 1, 5, 6, and 9. -------------------------------------------------------------------------------- /Module 2/MasteringPredictiveAnalyticswithPython_Code/SoftwareList.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Python-Advanced-Predictive-Analytics/eda343c48e58b613c28a21a35155f213f4b1771a/Module 2/MasteringPredictiveAnalyticswithPython_Code/SoftwareList.pdf -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ### Download a free PDF 5 | 6 | If you have already purchased a print or Kindle version of this book, you can get a DRM-free PDF version at no cost.
Simply click on the link to claim your free PDF.
7 |

https://packt.link/free-ebook/9781788992367

--------------------------------------------------------------------------------