In [2]:
%matplotlib inline
import numpy as np
from matplotlib import pyplot
import pandas as pd

Короче функция, которая домнажать вектор на случайную матрица!

$$X_{1\times n}R_{n\times k}=C_{1\times k}$$

, где: 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} $$

https://www.latex4technics.com/


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)


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-20-0d7d9a5ab59a> in <module>()
----> 1 mm(np.array([1,2, 1,132, 1,2]), 5)

<ipython-input-19-83b997f0d30b> in mm(x, k)
      2     if x.shape[0] > 1:
      3         x=x.T
----> 4     r = np.random.rand(x.shape[1],k)
      5     print(r)
      6     #print(x.dot(r))

IndexError: tuple index out of range

Вытаскивание даных из файла!


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()


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-a13ce4935187> in <module>()
      1 from sklearn.preprocessing import scale
----> 2 X_train_draw = scale(X_train[::, 0:2])
      3 X_test_draw = scale(X_test[::, 0:2])
      4 
      5 clf = RandomForestClassifier(n_estimators=100, n_jobs=-1)

NameError: name 'X_train' is not defined

In [13]:
x = np.eye(1, 18)
x[0][12] = 5
print(x)


[[ 1.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  5.  0.  0.  0.  0.  0.]]

In [ ]: