Skip to content

Commit 2b0f8c7

Browse files
Second server backup
1 parent 55c17c1 commit 2b0f8c7

27 files changed

+656
-0
lines changed

Server backup 2/Scripts/custom.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Simple Linear Regression
2+
# Importing the libraries
3+
import numpy as np
4+
import pandas as pd
5+
import pickle
6+
7+
# Importing the dataset
8+
dataset = pd.read_csv('/home/soumitra/Working/Salary_Data.csv')
9+
X = dataset.iloc[:, :-1].values
10+
y = dataset.iloc[:, 1].values
11+
12+
# Splitting the dataset into the Training set and Test set
13+
from sklearn.cross_validation import train_test_split
14+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size =0.33,random_state = 0)
15+
16+
# Feature Scaling
17+
"""from sklearn.preprocessing import StandardScaler
18+
sc_X = StandardScaler()
19+
X_train = sc_X.fit_transform(X_train)
20+
X_test = sc_X.transform(X_test)
21+
sc_y = StandardScaler()
22+
y_train = sc_y.fit_transform(y_train)"""
23+
24+
# Fitting Simple Linear Regression to the Training set
25+
from sklearn.linear_model import LinearRegression
26+
regressor = LinearRegression()
27+
regressor.fit(X_train, y_train)
28+
29+
# Predicting the Test set results
30+
y_pred = regressor.predict(X_test)
31+
coef_ = regressor.coef_
32+
intercept_ = regressor.intercept_
33+
34+
# Score of prediction model
35+
from sklearn.metrics import r2_score
36+
score = r2_score(y_test, y_pred)
37+
pickle.dump([y_pred, score, coef_, intercept_], open("/home/soumitra/attributes.p", "wb"), protocol = 2)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Decision Tree Classification
2+
3+
# Importing the libraries
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
import pandas as pd
7+
import pickle
8+
9+
# Importing the dataset
10+
dataset = open(workdata, 'r')
11+
mat = dataset.readlines()
12+
time = []
13+
for row in mat:
14+
pres = row.split()
15+
pres = [float(ro) for ro in pres]
16+
time.append(pres)
17+
18+
time = np.array(time)
19+
20+
X_train = time[:, :-1]
21+
y_train = time[:, -1]
22+
23+
# Fitting Decision Tree Classification to the Training set
24+
from sklearn.tree import DecisionTreeClassifier
25+
classifier = DecisionTreeClassifier(parameters)
26+
classifier.fit(X_train, y_train)
27+
28+
pickle.dump(classifier,open(hoemdir + "/attributes.p", "wb"), protocol = 2 )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Regression Template
2+
3+
# Importing the libraries
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
import pandas as pd
7+
import pickle
8+
9+
# Importing the dataset
10+
# Importing the dataset
11+
dataset = open(workdata, 'r')
12+
mat = dataset.readlines()
13+
time = []
14+
for row in mat:
15+
pres = row.split()
16+
pres = [float(ro) for ro in pres]
17+
time.append(pres)
18+
19+
time = np.array(time)
20+
21+
X = time[:, :-1]
22+
y = time[:, -1]
23+
24+
# Splitting the dataset into the Training set and Test set
25+
"""from sklearn.cross_validation import train_test_split
26+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.2, random_state = 0)"""
27+
28+
# Feature Scaling
29+
"""
30+
from sklearn.preprocessing import StandardScaler
31+
sc_X = StandardScaler()
32+
X= sc_X.fit_transform(X)
33+
sc_y = StandardScaler()
34+
y = sc_y.fit_transform(y)"""
35+
36+
# Fitting the Regression Model to the dataset
37+
# Create your regressor here
38+
from sklearn.tree import DecisionTreeRegressor
39+
regressor = DecisionTreeRegressor(parameters)
40+
regressor.fit(X, y)
41+
42+
pickle.dump(regressor,open(hoemdir + "/attributes.p", "wb"), protocol = 2 )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Hierarchical Clustering
2+
3+
# Importing the libraries
4+
import numpy as np
5+
import pandas as pd
6+
import pickle
7+
8+
# Importing the dataset
9+
dataset = open('/home/soumitra/Working/data', 'r')
10+
mat = dataset.readlines()
11+
time = []
12+
for row in mat:
13+
pres = row.split()
14+
pres = [float(ro) for ro in pres]
15+
time.append(pres)
16+
17+
time = np.array(time)
18+
X = time
19+
20+
# Fitting Hierarchical Clustering to the dataset
21+
from sklearn.cluster import AgglomerativeClustering
22+
hc = AgglomerativeClustering(parameters)
23+
y_hc = hc.fit_predict(X)
24+
25+
pickle.dump(y_hc ,open("/home/soumitra/attributes.p", "wb"), protocol = 2 )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# K-Means Clustering
2+
3+
# Importing the libraries
4+
import numpy as np
5+
import matplotlib.pyplot as plt
6+
import pandas as pd
7+
import pickle
8+
9+
# Importing the dataset
10+
dataset = open(workdata, 'r')
11+
mat = dataset.readlines()
12+
time = []
13+
for row in mat:
14+
pres = row.split()
15+
pres = [float(ro) for ro in pres]
16+
time.append(pres)
17+
18+
time = np.array(time)
19+
X = time
20+
21+
# Using the elbow method to find the optimal number of clusters
22+
from sklearn.cluster import KMeans
23+
kmeans = KMeans(parameters)
24+
kmeans.fit(X)
25+
26+
27+
28+
# Export the results to pickle file
29+
pickle.dump(kmeans,open(homedir + "/attributes.p", "wb"), protocol = 2 )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# K-Nearest Neighbors (K-NN)
2+
# Classification template
3+
4+
# Importing the libraries
5+
import numpy as np
6+
import pickle
7+
import pandas as pd
8+
9+
# Importing the dataset
10+
dataset = open(workdata, 'r')
11+
mat = dataset.readlines()
12+
time = []
13+
for row in mat:
14+
pres = row.split()
15+
pres = [float(ro) for ro in pres]
16+
time.append(pres)
17+
18+
time = np.array(time)
19+
X = time[:, :-1]
20+
y = time[:, -1]
21+
22+
# Fitting classifier to the Training set
23+
from sklearn.neighbors import KNeighborsClassifier
24+
classifier = KNeighborsClassifier(parameters)
25+
classifier.fit(X, y)
26+
27+
# Export results to pickle file
28+
pickle.dump(classifier,open(homedir + "/attributes.p", "wb"), protocol = 2 )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Simple Linear Regression
2+
# Importing the libraries
3+
import numpy as np
4+
import pickle
5+
6+
# Importing the dataset
7+
dataset = open(workdata, 'r')
8+
mat = dataset.readlines()
9+
time = []
10+
for row in mat:
11+
pres = row.split()
12+
pres = [float(ro) for ro in pres]
13+
time.append(pres)
14+
15+
time = np.array(time)
16+
X = time[:, :-1]
17+
y = time[:, -1]
18+
19+
# Fitting Simple Linear Regression to the Training set
20+
from sklearn.linear_model import LinearRegression
21+
regressor = LinearRegression()
22+
regressor.fit(X, y)
23+
24+
pickle.dump(regressor, open(homedir + "/attributes.p", "wb"), protocol = 2)

Server backup 2/Scripts/logistic.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
# Importing the libraries
3+
import numpy as np
4+
import pickle
5+
6+
# Importing the dataset
7+
# Importing the dataset
8+
dataset = open('/home/soumitra/Working/data', 'r')
9+
mat = dataset.readlines()
10+
time = []
11+
for row in mat:
12+
pres = row.split()
13+
pres = [float(ro) for ro in pres]
14+
time.append(pres)
15+
16+
time = np.array(time)
17+
18+
X = time[:, :-1]
19+
y = time[:, -1]
20+
21+
#Fitting dataset to logistic regression
22+
from sklearn.linear_model import LogisticRegression
23+
classifier = LogisticRegression()
24+
classifier.fit(X, y)
25+
26+
pickle.dump(classifier,open("/home/soumitra/attributes.p", "wb"), protocol = 2 )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
# Importing the libraries
3+
import numpy as np
4+
import pickle
5+
6+
# Importing the dataset
7+
# Importing the dataset
8+
dataset = open(workdata, 'r')
9+
mat = dataset.readlines()
10+
time = []
11+
for row in mat:
12+
pres = row.split()
13+
pres = [float(ro) for ro in pres]
14+
time.append(pres)
15+
16+
time = np.array(time)
17+
18+
X = time[:, :-1]
19+
y = time[:, -1]
20+
21+
#Fitting dataset to logistic regression
22+
from sklearn.linear_model import LogisticRegression
23+
classifier = LogisticRegression(parameters)
24+
classifier.fit(X, y)
25+
26+
pickle.dump(classifier,open(homedir + "/attributes.p", "wb"), protocol = 2 )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Mon July 8 23:31:52 2017
4+
5+
@author: Mandar
6+
"""
7+
8+
# Data Preprocessing Template
9+
10+
# Importing the libraries
11+
import numpy as np
12+
import matplotlib.pyplot as plt
13+
import pandas as pd
14+
import pickle
15+
16+
# Importing the dataset
17+
dataset = open(workdata, 'r')
18+
mat = dataset.readlines()
19+
time = []
20+
for row in mat:
21+
pres = row.split()
22+
pres = [float(ro) for ro in pres]
23+
time.append(pres)
24+
25+
time = np.array(time)
26+
27+
X = time[:, :-1]
28+
y = time[:, -1]
29+
30+
31+
#Fitting mutilpls linear regreesion to training set
32+
from sklearn.linear_model import LinearRegression
33+
regressor = LinearRegression(parameters)
34+
regressor.fit(X, y)
35+
36+
37+
pickle.dump(regressor ,open(homedir + "attributes.p", "wb"), protocol = 2 )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Naive Bayes
2+
3+
# Importing the libraries
4+
import numpy as np
5+
import pandas as pd
6+
import pickle
7+
8+
# Importing the dataset
9+
dataset = open(workdata, 'r')
10+
mat = dataset.readlines()
11+
time = []
12+
for row in mat:
13+
pres = row.split()
14+
pres = [float(ro) for ro in pres]
15+
time.append(pres)
16+
17+
time = np.array(time)
18+
19+
X = time[:, :-1]
20+
y = time[:, -1]
21+
22+
# Fitting Naive Bayes to the Training set
23+
from sklearn.naive_bayes import GaussianNB
24+
classifier = GaussianNB(parameters)
25+
classifier.fit(X, y)
26+
27+
28+
pickle.dump(classifier,open(homedir + "/attributes.p", "wb"), protocol = 2 )
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Naive Bayes
2+
3+
# Importing the libraries
4+
import numpy as np
5+
import pandas as pd
6+
import pickle
7+
8+
# Importing the dataset
9+
dataset = open(workdata, 'r')
10+
mat = dataset.readlines()
11+
time = []
12+
for row in mat:
13+
pres = row.split()
14+
pres = [float(ro) for ro in pres]
15+
time.append(pres)
16+
17+
time = np.array(time)
18+
19+
X = time[:, :-1]
20+
y = time[:, -1]
21+
22+
# Fitting Naive Bayes to the Training set
23+
from sklearn.naive_bayes import GaussianNB
24+
classifier = GaussianNB(parameters)
25+
classifier.fit(X, y)
26+
27+
pickle.dump(classifier ,open("/home/soumitra/attributes.p", "wb"), protocol = 2 )
28+

0 commit comments

Comments
 (0)