Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pull for new code #1

Merged
merged 20 commits into from
Nov 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

19,948 changes: 19,948 additions & 0 deletions 2018-autumn/10k_articles.txt

Large diffs are not rendered by default.

Binary file added 2018-autumn/80k.tar.gz
Binary file not shown.
571 changes: 571 additions & 0 deletions 2018-autumn/Lecture-01-An Introduction to AI-ustccheng02.ipynb

Large diffs are not rendered by default.

338 changes: 184 additions & 154 deletions 2018-autumn/Lecture-01-An Introduction to AI.ipynb

Large diffs are not rendered by default.

2,614 changes: 2,614 additions & 0 deletions 2018-autumn/Lecture-2-Language-Model.ipynb

Large diffs are not rendered by default.

1,033 changes: 1,033 additions & 0 deletions 2018-autumn/Lesson-03-Best-First-Search-and-A-Start-Search.ipynb

Large diffs are not rendered by default.

Binary file added 2018-autumn/Lesson-03.pdf
Binary file not shown.
Binary file added 2018-autumn/lesson01-Part01.pdf
Binary file not shown.
Binary file added 2018-autumn/lesson01-Part02.pdf
Binary file not shown.
Binary file added 2018-autumn/lesson01.pdf
Binary file not shown.
95 changes: 95 additions & 0 deletions 2018-autumn/simple_machine_leanring.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# Created by mqgao at 2018/11/11

"""
Feature: #Enter feature name here
# Enter feature description here

Scenario: #Enter scenario name here
# Enter steps here

Test File Location: # Enter

"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import time


titanic_content = pd.read_csv(open('../../datasource/titanic_train.csv'))
titanic_content = titanic_content.dropna()
age_with_fare = titanic_content[['Age', 'Fare']]
age_with_fare = age_with_fare[ (age_with_fare['Age'] > 22) & (age_with_fare['Fare'] < 400) & (age_with_fare['Fare'] > 130)]
age = np.array(age_with_fare['Age'].tolist())
fare = np.array(age_with_fare['Fare'].tolist())


def loss(y_true, yhats): return np.mean(np.abs(y_true - yhats))


def model(x, a, b): return a * x + b

a = 1
b = 0

yhats = np.array([model(x, a, b) for x in age])


eps = 20

directions = [(1, -1), (1, 1), (-1, -1), (-1, 1)]

learning_rate = 1e-2

min_loss = float('inf')

batch = 0

while True:
if loss(y_true=fare, yhats=yhats) < eps: break

indices = np.random.choice(range(len(age)), size=10)

sample_x = age[indices]
sample_y = fare[indices]
# sample_x = age
# sample_y = fare

new_a, new_b = a, b

for d in directions:
da, db = d

if min_loss != float('inf'):
_a = a + da * min_loss * learning_rate
_b = b + db * min_loss * learning_rate
else:
_a, _b = a + db, b + db

y_hats = [model(x, _a, _b) for x in sample_x]
l = loss(sample_y, np.array([model(x, a + da, b + db) for x in sample_x]))

if l < min_loss:
min_loss = l
new_a, new_b = _a, _b

total = 10000

if batch % 100 == 0:
print('batch {}/ {} fare with {} * age + {}, with loss: {}'.format(batch, total, a, b, l))

if batch > total: break

batch += 1

a, b = new_a, new_b

# time.sleep(0.01)

plt.scatter(age, fare)
plt.plot(age, [model(x, a, b) for x in age])
plt.show()


## 1. 是否是可以学习的
## 2. 判断有没有学习
Empty file added test.txt
Empty file.