In [2]:
%matplotlib inline
import numpy as np
from matplotlib import pyplot
import pandas as pd
, где: R - рандомная матрица
$$ \begin{pmatrix}x_{11}\\x_{21}\\x_{31}\\x_{41}\\x_{51}\end{pmatrix}\begin{pmatrix}b_{11}&b_{12}&b_{13}&b_{14}\\b_{21}&b_{22}&b_{23}&b_{24}\\b_{31}&b_{32}&b_{33}&b_{34}\\b_{41}&b_{42}&b_{43}&b_{44}\end{pmatrix} $$
In [19]:
def mm(x, k):
if x.shape[0] > 1:
x=x.T
r = np.random.rand(x.shape[1],k)
print(r)
#print(x.dot(r))
return(x.dot(r))
In [20]:
mm(np.array([[1,2, 1,132, 1,2]]), 5)
https://habrahabr.ru/company/wunderfund/blog/316826/ http://www.karsdorp.io/python-course/
https://docs.scipy.org/doc/numpy/reference/index.html https://stepik.org/lesson/NumPy-%D0%BE%D1%81%D0%BD%D0%BE%D0%B2%D1%8B-16462/step/8?course=%D0%9D%D0%B5%D0%B9%D1%80%D0%BE%D0%BD%D0%BD%D1%8B%D0%B5-%D1%81%D0%B5%D1%82%D0%B8&unit=4283
In [1]:
from sklearn.preprocessing import scale
X_train_draw = scale(X_train[::, 0:2])
X_test_draw = scale(X_test[::, 0:2])
clf = RandomForestClassifier(n_estimators=100, n_jobs=-1)
clf.fit(X_train_draw, y_train)
x_min, x_max = X_train_draw[:, 0].min() - 1, X_train_draw[:, 0].max() + 1
y_min, y_max = X_train_draw[:, 1].min() - 1, X_train_draw[:, 1].max() + 1
h = 0.02
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))
pred = clf.predict(np.c_[xx.ravel(), yy.ravel()])
pred = pred.reshape(xx.shape)
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
cmap_light = ListedColormap(['#FFAAAA', '#AAFFAA', '#AAAAFF'])
cmap_bold = ListedColormap(['#FF0000', '#00FF00', '#0000FF'])
plt.figure()
plt.pcolormesh(xx, yy, pred, cmap=cmap_light)
plt.scatter(X_train_draw[:, 0], X_train_draw[:, 1],
c=y_train, cmap=cmap_bold)
plt.xlim(xx.min(), xx.max())
plt.ylim(yy.min(), yy.max())
plt.title("Score: %.0f percents" % (clf.score(X_test_draw, y_test) * 100))
plt.show()
In [13]:
x = np.eye(1, 18)
x[0][12] = 5
print(x)
In [ ]: