Skip to content

Commit 2abce13

Browse files
author
morvan
committed
update print function
1 parent 9a3fc8a commit 2abce13

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+82
-15
lines changed

numpy&pandas/11_pandas_intro.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import pandas as pd
1011
import numpy as np
1112

numpy&pandas/12_selection.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
77
"""
8+
from __future__ import print_function
89
import pandas as pd
910
import numpy as np
1011

numpy&pandas/13_set_value.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import pandas as pd
1011
import numpy as np
1112

numpy&pandas/14_nan.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import pandas as pd
1011
import numpy as np
1112

numpy&pandas/15_read_to/15_read_to.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
77
"""
8+
from __future__ import print_function
89
import pandas as pd
910

1011
# read from

numpy&pandas/16_concat.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import pandas as pd
1011
import numpy as np
1112

numpy&pandas/17_merge.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import pandas as pd
1011

1112
# merging two df by key/keys. (may be used in database)

numpy&pandas/18_plot.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import pandas as pd
1011
import numpy as np
1112
import matplotlib.pyplot as plt

real world examples/bank_marketing_learning/bank_marketing_sk.py

+25-15
Original file line numberDiff line numberDiff line change
@@ -59,37 +59,47 @@ def feature_utility(data, selected_feature_name, target_name):
5959
plt.legend([bar[0] for bar in bars], target_classes, loc='best')
6060
plt.show()
6161

62+
def encode_label(data):
63+
la_en = preprocessing.LabelEncoder()
64+
for col in ['job', 'marital', 'education', 'default', 'housing', 'loan',
65+
'contact', 'month', 'poutcome', 'y']:
66+
data[col] = bank_data[col].astype('category')
67+
data[col] = la_en.fit_transform(bank_data[col])
68+
return data
69+
6270
dataset_path = ['bank.csv', 'bank-full.csv']
6371
bank_data = pd.read_csv(dataset_path[1], sep=';')
72+
print(bank_data.head())
6473

6574
# good categorical features: job, marital, education, housing, loan, contact, month, poutcome
6675
# bad categorical features: default
6776
# feature_utility(bank_data, 'housing', 'y')
6877

69-
le_en = preprocessing.LabelEncoder()
70-
for col in ['job', 'marital', 'education', 'default', 'housing', 'loan',
71-
'contact', 'month', 'poutcome', 'y']:
72-
bank_data[col] = bank_data[col].astype('category')
73-
bank_data[col] = le_en.fit_transform(bank_data[col])
78+
bank_data = encode_label(bank_data)
7479
# print(bank_data.dtypes)
7580
# print(bank_data.head())
7681

7782
X_data, y_data = bank_data.iloc[:, :-1], bank_data.iloc[:, -1]
83+
# show the percentage of answer yes and no.
84+
answer_no, answer_yes = y_data.value_counts()
85+
print('Percentage of answering no: ', answer_no/(answer_no+answer_yes))
86+
7887
X_train, X_test, y_train, y_test = train_test_split(
7988
X_data, y_data,
8089
test_size=0.2)
8190

82-
dt_clf = DecisionTreeClassifier()
83-
rf_clf = RandomForestClassifier()
91+
dt_clf = DecisionTreeClassifier(class_weight='balanced',)
92+
rf_clf = RandomForestClassifier(class_weight='balanced')
93+
# randomize the data, and run the cross validation for 5 times
8494
cv = ShuffleSplit(X_data.shape[0], n_iter=5,
85-
test_size=0.2, random_state=0)
86-
print(cross_val_score(dt_clf, X_data, y_data, cv=cv, scoring='accuracy').mean())
87-
print(cross_val_score(rf_clf, X_data, y_data, cv=cv, scoring='accuracy').mean())
88-
89-
dt_clf.fit(X_train, y_train)
90-
print(dt_clf.score(X_test, y_test))
91-
rf_clf.fit(X_train, y_train)
92-
print(rf_clf.score(X_test, y_test))
95+
test_size=0.3, random_state=0)
96+
print(cross_val_score(dt_clf, X_data, y_data, cv=cv, scoring='f1').mean())
97+
print(cross_val_score(rf_clf, X_data, y_data, cv=cv, scoring='f1').mean())
98+
99+
# dt_clf.fit(X_train, y_train)
100+
# print(dt_clf.score(X_test, y_test))
101+
# rf_clf.fit(X_train, y_train)
102+
# print(rf_clf.score(X_test, y_test))
93103

94104
# print(rf_clf.predict(X_test.iloc[10, :][np.newaxis, :]))
95105
# print(y_test.iloc[10])

sklearnTUT/sk10_cross_validation3.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
from sklearn.learning_curve import validation_curve
1011
from sklearn.datasets import load_digits
1112
from sklearn.svm import SVC

sklearnTUT/sk11_save.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
from sklearn import svm
1011
from sklearn import datasets
1112

sklearnTUT/sk4_learning_pattern.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
from sklearn import datasets
1011
from sklearn.cross_validation import train_test_split
1112
from sklearn.neighbors import KNeighborsClassifier

sklearnTUT/sk5_datasets.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
from sklearn import datasets
1011
from sklearn.linear_model import LinearRegression
1112
import matplotlib.pyplot as plt

sklearnTUT/sk6_model_attribute_method.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
from sklearn import datasets
1011
from sklearn.linear_model import LinearRegression
1112

sklearnTUT/sk7_normalization.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
from sklearn import preprocessing
1011
import numpy as np
1112
from sklearn.cross_validation import train_test_split

sklearnTUT/sk8_cross_validation/for_you_to_practice.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
from sklearn.datasets import load_iris
1011
from sklearn.cross_validation import train_test_split
1112
from sklearn.neighbors import KNeighborsClassifier

sklearnTUT/sk8_cross_validation/full_code.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
from sklearn.datasets import load_iris
1011
from sklearn.cross_validation import train_test_split
1112
from sklearn.neighbors import KNeighborsClassifier

sklearnTUT/sk9_cross_validation2.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
from sklearn.learning_curve import learning_curve
1011
from sklearn.datasets import load_digits
1112
from sklearn.svm import SVC

tensorflowTUT/tensorflow10_def_add_layer.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011

1112

tensorflowTUT/tensorflow11_build_network.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
import numpy as np
1112

tensorflowTUT/tensorflow12_plut_result.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
import numpy as np
1112
import matplotlib.pyplot as plt

tensorflowTUT/tensorflow6_session.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011

1112
matrix1 = tf.constant([[3, 3]])

tensorflowTUT/tensorflow7_variable.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011

1112
state = tf.Variable(0, name='counter')

tensorflowTUT/tensorflow8_feeds.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011

1112
input1 = tf.placeholder(tf.float32)

tensorflowTUT/tf11_build_network/for_you_to_practice.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
import numpy as np
1112

tensorflowTUT/tf11_build_network/full_code.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
import numpy as np
1112
import matplotlib.pyplot as plt

tensorflowTUT/tf12_plot_result/for_you_to_practice.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
import numpy as np
1112
import matplotlib.pyplot as plt

tensorflowTUT/tf12_plot_result/full_code.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
import numpy as np
1112
import matplotlib.pyplot as plt

tensorflowTUT/tf14_tensorboard/for_you_to_practice.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011

1112

tensorflowTUT/tf14_tensorboard/full_code.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011

1112

tensorflowTUT/tf15_tensorboard/for_you_to_practice.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
import numpy as np
1112

tensorflowTUT/tf15_tensorboard/full_code.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
import numpy as np
1112

tensorflowTUT/tf16_classification/for_you_to_practice.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011

1112

tensorflowTUT/tf16_classification/full_code.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
from tensorflow.examples.tutorials.mnist import input_data
1112
# number 1 to 10 data

tensorflowTUT/tf17_dropout/for_you_to_practice.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
from sklearn.datasets import load_digits
1112
from sklearn.cross_validation import train_test_split

tensorflowTUT/tf17_dropout/full_code.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
from sklearn.datasets import load_digits
1112
from sklearn.cross_validation import train_test_split

tensorflowTUT/tf18_CNN2/for_you_to_practice.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
from tensorflow.examples.tutorials.mnist import input_data
1112
# number 1 to 10 data

tensorflowTUT/tf18_CNN2/full_code.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
from tensorflow.examples.tutorials.mnist import input_data
1112
# number 1 to 10 data

tensorflowTUT/tf18_CNN3/for_you_to_practice.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
from tensorflow.examples.tutorials.mnist import input_data
1112
# number 1 to 10 data

tensorflowTUT/tf18_CNN3/full_code.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
from tensorflow.examples.tutorials.mnist import input_data
1112
# number 1 to 10 data

tensorflowTUT/tf19_saver.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
import numpy as np
1112

tensorflowTUT/tf5_example2/for_you_to_practice.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
import numpy as np
1112

tensorflowTUT/tf5_example2/full_code.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
Please note, this code is only for python 3+. If you are using python 2+, please modify the code accordingly.
88
"""
9+
from __future__ import print_function
910
import tensorflow as tf
1011
import numpy as np
1112

0 commit comments

Comments
 (0)