Skip to content

Commit 2d56315

Browse files
author
sheng.xu
committed
xs
1 parent 5ec8a5e commit 2d56315

File tree

12 files changed

+597
-231
lines changed

12 files changed

+597
-231
lines changed

.idea/workspace.xml

Lines changed: 413 additions & 46 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Chapter_1 Logistic Regression/data.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,4 @@
197197
4.15244831176753 1.44597290703838 1
198198
9.55986996363196 1.13832040773527 1
199199
1.63276516895206 0.446783742774178 1
200-
9.38532498107474 0.913169554364942 1
200+
9.38532498107474 0.913169554364942 1

Chapter_1 Logistic Regression/load_test.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ def load_data(file_name):
2626
feature_data.append(feature_tmp)
2727
label_data.append(lable_tmp)
2828
f.close() # 关闭文件
29-
print feature_data
30-
print "======"
31-
print label_data
3229
return np.mat(feature_data), np.mat(label_data)
3330

3431
if __name__ == "__main__":
@@ -38,4 +35,3 @@ def load_data(file_name):
3835
# 2、训练LR模型
3936
print feature
4037
print label
41-
print "---------- 2.training ------------"

Chapter_1 Logistic Regression/lr_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ def save_result(file_name, result):
7878
print "---------- 1.load model ------------"
7979
w = load_weight("weights")
8080
n = np.shape(w)[1]
81+
print np.shape(w)
8182
# 2、导入测试数据
8283
print "---------- 2.load data ------------"
8384
testData = load_data("test_data", n)
@@ -86,5 +87,5 @@ def save_result(file_name, result):
8687
h = predict(testData, w)#进行预测
8788
# 4、保存最终的预测结果
8889
print "---------- 4.save prediction ------------"
89-
print np.mat(h)
90-
save_result("result.model", np.mat(h))
90+
#print np.mat(h)
91+
save_result("result", np.mat(h))

Chapter_1 Logistic Regression/lr_train.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def lr_train_bgd(feature, label, maxCycle, alpha):
4444
output: w(mat):权重
4545
'''
4646
n = np.shape(feature)[1] # 特征个数
47-
w = np.mat(np.ones((n, 1))) # 初始化权重
47+
# (200,3) np.shape(feature)[0] 表示特征矩阵的行数,np.shape(feature)[1] 表示特征矩阵的个数
48+
w = np.mat(np.ones((n, 1))) # 初始化权重 初始化三个1的一个矩阵
4849
i = 0
4950
while i <= maxCycle: # 在最大迭代次数的范围内
5051
i += 1 # 当前的迭代次数
@@ -89,9 +90,12 @@ def save_model(file_name, w):
8990
# 1、导入训练数据
9091
print "---------- 1.load data ------------"
9192
feature, label = load_data("data.txt")
93+
print feature
94+
print label
9295
# 2、训练LR模型
9396
print "---------- 2.training ------------"
9497
w = lr_train_bgd(feature, label, 1000, 0.01)
98+
print w
9599
# 3、保存最终的模型
96100
print "---------- 3.save model ------------"
97101
save_model("weights", w)
15 Bytes
Binary file not shown.

Chapter_1 Logistic Regression/result.model

Lines changed: 0 additions & 1 deletion
This file was deleted.

Chapter_1 Logistic Regression/weights.model

Lines changed: 0 additions & 1 deletion
This file was deleted.
0 Bytes
Binary file not shown.

Chapter_3 Factorization Machine/data.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,4 @@
197197
2.74262556141998 -0.254027266166219 1
198198
1.24804345641085 -0.241408809531456 1
199199
0.808431917613837 -0.242017996831424 1
200-
6.74094601972670 -0.373633464603415 1
200+
6.74094601972670 -0.373633464603415 1

0 commit comments

Comments
 (0)