You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

simple_classification.py 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # ---
  2. # jupyter:
  3. # jupytext_format_version: '1.2'
  4. # kernelspec:
  5. # display_name: Python 3
  6. # language: python
  7. # name: python3
  8. # ---
  9. __author__ = 'm.bashari'
  10. import numpy as np
  11. from sklearn import datasets, linear_model
  12. import matplotlib.pyplot as plt
  13. def generate_data():
  14. np.random.seed(0)
  15. X, y = datasets.make_moons(200, noise=0.20)
  16. return X, y
  17. def visualize(X, y, clf):
  18. # plt.scatter(X[:, 0], X[:, 1], s=40, c=y, cmap=plt.cm.Spectral)
  19. # plt.show()
  20. plot_decision_boundary(lambda x: clf.predict(x), X, y)
  21. plt.title("Logistic Regression")
  22. def plot_decision_boundary(pred_func, X, y):
  23. # Set min and max values and give it some padding
  24. x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
  25. y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
  26. h = 0.01
  27. # Generate a grid of points with distance h between them
  28. xx, yy = np.meshgrid(np.arange(x_min, x_max, h), np.arange(y_min, y_max, h))
  29. # Predict the function value for the whole gid
  30. Z = pred_func(np.c_[xx.ravel(), yy.ravel()])
  31. Z = Z.reshape(xx.shape)
  32. # Plot the contour and training examples
  33. plt.contourf(xx, yy, Z, cmap=plt.cm.Spectral)
  34. plt.scatter(X[:, 0], X[:, 1], c=y, cmap=plt.cm.Spectral)
  35. plt.show()
  36. def classify(X, y):
  37. clf = linear_model.LogisticRegressionCV()
  38. clf.fit(X, y)
  39. return clf
  40. def main():
  41. X, y = generate_data()
  42. # visualize(X, y)
  43. clf = classify(X, y)
  44. visualize(X, y, clf)
  45. if __name__ == "__main__":
  46. main()

机器学习越来越多应用到飞行器、机器人等领域,其目的是利用计算机实现类似人类的智能,从而实现装备的智能化与无人化。本课程旨在引导学生掌握机器学习的基本知识、典型方法与技术,通过具体的应用案例激发学生对该学科的兴趣,鼓励学生能够从人工智能的角度来分析、解决飞行器、机器人所面临的问题和挑战。本课程主要内容包括Python编程基础,机器学习模型,无监督学习、监督学习、深度学习基础知识与实现,并学习如何利用机器学习解决实际问题,从而全面提升自我的《综合能力》。