{"id":273397,"date":"2016-02-02T12:09:02","date_gmt":"2016-02-02T09:09:02","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=273397"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=273397","title":{"rendered":"\u041c\u0430\u0448\u0438\u043d\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043e\u0442 Octave\\Matlab \u043a Python"},"content":{"rendered":"<p>       \u0420\u0435\u0448\u0438\u043b \u044f \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u0441 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c\u044e, \u043a\u0430\u043a Machine learning. \u041f\u043e\u0441\u043b\u0435 \u043d\u0435\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0438\u0441\u043a\u043e\u0432 \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u043a\u0443\u0440\u0441 \u0421\u0442\u044d\u043d\u0444\u043e\u0440\u0434\u0441\u043a\u043e\u0433\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430 Machine learning. \u0412 \u043d\u0435\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u044b \u0438 \u0434\u0430\u0435\u0442\u0441\u044f \u0448\u0438\u0440\u043e\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e machine learning, datamining, and statistical pattern recognition. \u0411\u044b\u043b \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0432 \u044d\u0442\u043e\u043c \u043a\u0443\u0440\u0441\u0435 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0438\u043d\u0443\u0441 \u043a\u0430\u043a Python \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430- \u0434\u043e\u043c\u0430\u0448\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0430 Octave\\Matlab. \u0412 \u0438\u0442\u043e\u0433\u0435 \u044f \u043d\u0435 \u043f\u043e\u0436\u0430\u043b\u0435\u043b, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e \u043d\u043e\u0432\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e \u043a\u0430\u043a \u0443\u0447\u0435\u0431\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u0435\u0441\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0430 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0440\u0435\u0448\u0438\u043b \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043e\u043c\u0430\u0448\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043d\u0430 Python. \u0422\u043e \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043b\u0435\u0436\u0438\u0442 \u043d\u0430 GitHub <a href=\"https:\/\/github.com\/mlyundin\/Machine-Learning\">\u0442\u0443\u0442<\/a>.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/5ac\/6c6\/06a\/5ac6c606a2074d43ad5d8be1eda31bb8.png\"\/><br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<pre><code class=\"python\">if __name__ == '__main__':     data = sio.loadmat('ex6data1.mat')     y = data['y'].astype(np.float64)     X = data['X']      visualize_boundary_linear(X, y, None)      C = 1     model = svm_train(X, y, C, linear_kernel, 0.001, 20)     visualize_boundary_linear(X, y, model)      C = 100     model = svm_train(X, y, C, linear_kernel, 0.001, 20)     visualize_boundary_linear(X, y, model)      x1 = np.array([1, 2, 1], dtype=np.float64)     x2 = np.array([0, 4, -1], dtype=np.float64)     sigma = 2.0     sim = gaussian_kernel(x1, x2, sigma);      print('Gaussian Kernel between x1 = [1; 2; 1], x2 = [0; 4; -1], sigma = 0.5 : (this value should be about 0.324652)')     print('Actual = {}'.format(sim))      data = sio.loadmat('ex6data2.mat')     y = data['y'].astype(np.float64)     X = data['X']      visualize_data(X, y).show()      C = 1.0     sigma = 0.1      partialGaussianKernel = partial(gaussian_kernel, sigma=sigma)     partialGaussianKernel.__name__ = gaussian_kernel.__name__     model= svm_train(X, y, C, partialGaussianKernel)     visualize_boundary(X, y, model)      data = sio.loadmat('ex6data3.mat')     y = data['y'].astype(np.float64)     X = data['X']     Xval = data['Xval']     yval = data['yval'].astype(np.float64)      visualize_data(X, y).show()      best_C = 0     best_sigma = 0     best_error = len(yval)     best_model = None      for C in [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30]:         for sigma in [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30]:             partialGaussianKernel = partial(gaussian_kernel, sigma=sigma)             partialGaussianKernel.__name__ = gaussian_kernel.__name__              model= svm_train(X, y, C, partialGaussianKernel)             ypred = svm_predict(model, Xval)             error = np.mean(ypred != yval.ravel())             if error &lt; best_error:                 best_error = error                 best_C = C                 best_sigma = sigma                 best_model = model      visualize_boundary(X, y, best_model) <\/code><\/pre>\n<p>  \u041d\u043e \u0442\u0430\u043a \u043a\u0430\u043a Python \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u044f \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u044d\u0442\u0438\u0445 \u0446\u0435\u043b\u0435\u0439 scikit-learn, \u044f \u043f\u043e\u043f\u044b\u0442\u0430\u043b\u0441\u044f \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u044d\u0442\u043e\u0439 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438(\u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0444\u0430\u0439\u043b\u044b \u0441 \u0441\u0443\u0444\u0444\u0438\u043a\u0441\u043e\u043c sklearn). \u041a\u0430\u043a \u0438 \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u043a\u043e\u0434 \u0441 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u044b\u0435 \u0438 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u0435\u0435 \u0438 \u043f\u043e\u043d\u044f\u0442\u043d\u0435\u0435(\u0441 \u043c\u043e\u0435\u0439 \u0442\u043e\u0447\u043a\u0438 \u0437\u0440\u0435\u043d\u0438\u044f).<\/p>\n<pre><code class=\"python\">if __name__ == '__main__':     data = sio.loadmat('ex6data1.mat')     y = data['y'].astype(np.float64).ravel()     X = data['X']     visualize_boundary(X, y, None)      C = 1     lsvc = LinearSVC(C=C, tol=0.001)     lsvc.fit(X, y)     svc = SVC(C=C, tol=0.001, kernel='linear')     svc.fit(X, y)     visualize_boundary(X, y, {'SVM(linear kernel) C = {}'.format(C): svc,                               'LinearSVC C = {}'.format(C): lsvc})      C = 100     lsvc = LinearSVC(C=C, tol=0.001)     lsvc.fit(X, y)     svc = SVC(C=C, tol=0.001, kernel='linear')     svc.fit(X, y)     visualize_boundary(X, y, {'SVM(linear kernel) C = {}'.format(C): svc,                               'LinearSVC C = {}'.format(C): lsvc})      data = sio.loadmat('ex6data2.mat')     y = data['y'].astype(np.float64).ravel()     X = data['X']      visualize_boundary(X, y)      C = 1.0     sigma = 0.1     gamma = sigma_to_gamma(sigma)     svc = SVC(C=C, tol=0.001, kernel='rbf', gamma=gamma)     svc.fit(X, y)     visualize_boundary(X, y, {'SVM(rbf kernel) C = {}'.format(C): svc})      data = sio.loadmat('ex6data3.mat')     y = data['y'].astype(np.float64).ravel()     X = data['X']     Xval = data['Xval']     yval = data['yval'].astype(np.float64).ravel()     visualize_boundary(X, y)      C_coefs = [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30]     sigma_coefs = [0.01, 0.03, 0.1, 0.3, 1, 3, 10, 30]      svcs = (SVC(C=C, gamma=sigma_to_gamma(sigma), tol=0.001, kernel='rbf') for C in C_coefs for sigma in sigma_coefs)     best_model = max(svcs, key=lambda svc: svc.fit(X, y).score(Xval, yval))     visualize_boundary(X, y, {'Best model(C={}, gamma={})'.format(best_model.C, best_model.gamma): best_model})      #Let's do the similar thing but using sklearn feature     X_all = np.vstack((X, Xval))     y_all = np.concatenate((y, yval))      parameters = {'C':C_coefs, 'gamma': map(sigma_to_gamma, sigma_coefs)}     svr = SVC(tol=0.001, kernel='rbf')     clf = GridSearchCV(svr, parameters, cv=2)     clf.fit(X_all, y_all)     visualize_boundary(X, y, {'Best model(C={}, gamma={})'.format(clf.best_params_['C'], clf.best_params_['gamma']): clf})  <\/code><\/pre>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/0d1\/b2c\/5e5\/0d1b2c5e59a2489a8ddc8fbadc08a565.png\"\/><\/p>\n<p>  P.S.<br \/>  \u0414\u043b\u044f \u0442\u0435\u0445 \u043a\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 Sklearn \u044f \u0431\u044b \u043f\u043e\u0441\u043e\u0432\u0435\u0442\u043e\u0432\u0430\u043b:<br \/>  <a href=\"https:\/\/www.udacity.com\/course\/viewer#!\/c-ud120\">\u041a\u0443\u0440\u0441 \u043d\u0430 udacity<\/a><br \/>  <a href=\"https:\/\/www.youtube.com\/watch?v=HjAB45qsx_c\">\u0412\u0438\u0434\u0435\u043e 1 \u0441 pycon<\/a><br \/>  <a href=\"https:\/\/www.youtube.com\/watch?v=FOZvHx-43pg\">\u0412\u0438\u0434\u0435\u043e 2 \u0441 pycon<\/a><\/p>\n<p>  P.P.S<br \/>  \u0414\u043b\u044f \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b <a href=\"https:\/\/www.continuum.io\/downloads\">\u0434\u0438\u0441\u0442\u0440\u0438\u0431\u0443\u0442\u0438\u0432 Anaconda<\/a>               <\/p>\n<div class=\"clear\"><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/276369\/\"> https:\/\/habrahabr.ru\/post\/276369\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>       \u0420\u0435\u0448\u0438\u043b \u044f \u043f\u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0441\u044f \u0441 \u0442\u0430\u043a\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u0439 \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u043e\u0431\u043b\u0430\u0441\u0442\u044c\u044e, \u043a\u0430\u043a Machine learning. \u041f\u043e\u0441\u043b\u0435 \u043d\u0435\u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0438\u0441\u043a\u043e\u0432 \u044f \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0438\u043b \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0439 \u043a\u0443\u0440\u0441 \u0421\u0442\u044d\u043d\u0444\u043e\u0440\u0434\u0441\u043a\u043e\u0433\u043e \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430 Machine learning. \u0412 \u043d\u0435\u043c \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u043e\u0441\u043d\u043e\u0432\u044b \u0438 \u0434\u0430\u0435\u0442\u0441\u044f \u0448\u0438\u0440\u043e\u043a\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e machine learning, datamining, and statistical pattern recognition. \u0411\u044b\u043b \u0434\u043b\u044f \u043c\u0435\u043d\u044f \u0432 \u044d\u0442\u043e\u043c \u043a\u0443\u0440\u0441\u0435 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043c\u0438\u043d\u0443\u0441 \u043a\u0430\u043a Python \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0441\u0442\u0430- \u0434\u043e\u043c\u0430\u0448\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043d\u0430 Octave\\Matlab. \u0412 \u0438\u0442\u043e\u0433\u0435 \u044f \u043d\u0435 \u043f\u043e\u0436\u0430\u043b\u0435\u043b, \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u043e \u043d\u043e\u0432\u043e\u043c \u044f\u0437\u044b\u043a\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e \u043a\u0430\u043a \u0443\u0447\u0435\u0431\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u0435\u0441\u043d\u043e\u0433\u043e \u0437\u043d\u0430\u043a\u043e\u043c\u0441\u0442\u0432\u0430 \u0441 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u043c\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430\u043c\u0438 \u0440\u0435\u0448\u0438\u043b \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u043e\u043c\u0430\u0448\u043d\u0438\u0435 \u0437\u0430\u0434\u0430\u043d\u0438\u044f \u043d\u0430 Python. \u0422\u043e \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u043b\u0435\u0436\u0438\u0442 \u043d\u0430 GitHub <a href=\"https:\/\/github.com\/mlyundin\/Machine-Learning\">\u0442\u0443\u0442<\/a>.<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/5ac\/6c6\/06a\/5ac6c606a2074d43ad5d8be1eda31bb8.png\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-273397","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/273397","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=273397"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/273397\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=273397"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=273397"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=273397"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}