Skip to content

Commit 36684db

Browse files
authored
Travis CI: Add pytest --doctest-modules machine_learning (#1016)
* Travis CI: Add pytest --doctest-modules neural_network Fixes #987 ``` neural_network/perceptron.py:123: in <module> sample.insert(i, float(input('value: '))) ../lib/python3.7/site-packages/_pytest/capture.py:693: in read raise IOError("reading from stdin while output is captured") E OSError: reading from stdin while output is captured -------------------------------------------------------------------------------- Captured stdout -------------------------------------------------------------------------------- ('\nEpoch:\n', 399) ------------------------ value: ``` * Adding fix from #1056 -- thanks @QuantumNovice * if __name__ == '__main__': * pytest --ignore=virtualenv # do not test our dependencies
1 parent 91c3c98 commit 36684db

File tree

5 files changed

+15
-134
lines changed

5 files changed

+15
-134
lines changed

machine_learning/perceptron.py

-124
This file was deleted.

machine_learning/random_forest_classification/random_forest_classification.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# Random Forest Classification
22

33
# Importing the libraries
4+
import os
45
import numpy as np
56
import matplotlib.pyplot as plt
67
import pandas as pd
78

89
# Importing the dataset
9-
dataset = pd.read_csv('Social_Network_Ads.csv')
10+
script_dir = os.path.dirname(os.path.realpath(__file__))
11+
dataset = pd.read_csv(os.path.join(script_dir, 'Social_Network_Ads.csv'))
1012
X = dataset.iloc[:, [2, 3]].values
1113
y = dataset.iloc[:, 4].values
1214

1315
# Splitting the dataset into the Training set and Test set
14-
from sklearn.cross_validation import train_test_split
16+
from sklearn.model_selection import train_test_split
1517
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
1618

1719
# Feature Scaling
@@ -66,4 +68,4 @@
6668
plt.xlabel('Age')
6769
plt.ylabel('Estimated Salary')
6870
plt.legend()
69-
plt.show()
71+
plt.show()

machine_learning/random_forest_regression/random_forest_regression.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Random Forest Regression
22

33
# Importing the libraries
4+
import os
45
import numpy as np
56
import matplotlib.pyplot as plt
67
import pandas as pd
78

89
# Importing the dataset
9-
dataset = pd.read_csv('Position_Salaries.csv')
10+
script_dir = os.path.dirname(os.path.realpath(__file__))
11+
dataset = pd.read_csv(os.path.join(script_dir, 'Position_Salaries.csv'))
1012
X = dataset.iloc[:, 1:2].values
1113
y = dataset.iloc[:, 2].values
1214

@@ -28,7 +30,7 @@
2830
regressor.fit(X, y)
2931

3032
# Predicting a new result
31-
y_pred = regressor.predict(6.5)
33+
y_pred = regressor.predict([[6.5]])
3234

3335
# Visualising the Random Forest Regression results (higher resolution)
3436
X_grid = np.arange(min(X), max(X), 0.01)
@@ -38,4 +40,4 @@
3840
plt.title('Truth or Bluff (Random Forest Regression)')
3941
plt.xlabel('Position level')
4042
plt.ylabel('Salary')
41-
plt.show()
43+
plt.show()

neural_network/perceptron.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ def sign(self, u):
113113

114114
exit = [-1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, -1, 1, 1, 1, 1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1]
115115

116-
if __name__ == '__main__':
117-
network = Perceptron(sample=samples, exit = exit, learn_rate=0.01, epoch_number=1000, bias=-1)
116+
network = Perceptron(sample=samples, exit = exit, learn_rate=0.01, epoch_number=1000, bias=-1)
118117

119-
network.training()
118+
network.training()
120119

120+
if __name__ == '__main__':
121121
while True:
122122
sample = []
123123
for i in range(3):
124-
sample.insert(i, float(input('value: ').strip()))
124+
sample.insert(i, float(input('value: ')))
125125
network.sort(sample)

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ opencv-python
77
pandas
88
pillow
99
pytest
10+
requests
1011
sklearn
1112
sympy
1213
tensorflow

0 commit comments

Comments
 (0)