{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Результат:\n",
"[[1 2 3 7 8]\n",
" [4 5 6 7 8]]\n"
]
}
],
"source": [
"import numpy as np\n",
"\n",
"# Создаем матрицу (2D массив)\n",
"matrix = np.array([[1, 2, 3],\n",
" [4, 5, 6]])\n",
"\n",
"# Создаем вектор (1D массив)\n",
"vector = np.array([7, 8])\n",
"\n",
"# Сконкатенируем каждый вектор матрицы с вектором\n",
"result = np.column_stack((matrix, np.tile(vector, (matrix.shape[0], 1))))\n",
"\n",
"print(\"Результат:\")\n",
"print(result)\n"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"137"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 93,
"metadata": {},
"outputs": [],
"source": [
"X = np.load('X.npy')\n",
"Y = np.load('y.npy')\n",
"X=X[-2:]\n",
"Y=Y[-2:]\n",
"np.save('X',X)\n",
"np.save('y',Y)"
]
},
{
"cell_type": "code",
"execution_count": 104,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(29263, 624)"
]
},
"execution_count": 104,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.shape"
]
},
{
"cell_type": "code",
"execution_count": 106,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(29265, 624)"
]
},
"execution_count": 106,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
".shape"
]
},
{
"cell_type": "code",
"execution_count": 109,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(29265,)"
]
},
"execution_count": 109,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Y.shape"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"\n",
"from sklearn.linear_model import LinearRegression\n",
"\n",
"dat = np.load('embeddings.npy')\n",
"data =np.column_stack((dat, dat))\n",
"datay = np.ones((data.shape[0]))*5\n",
"\n",
"data1 = np.column_stack((dat[1:], dat[:-1]))\n",
"datay1 = np.ones((data1.shape[0]))\n",
"\n",
"\n",
"X = np.load('X.npy') \n",
"Y = np.load('y.npy')\n",
"\n",
"\n",
"\n",
"X=np.concatenate((data,X))\n",
"Y=np.concatenate((datay,Y))\n",
"X = np.concatenate((data1,X))\n",
"Y = np.concatenate((datay1,Y))"
]
},
{
"cell_type": "code",
"execution_count": 132,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(29263, 624)"
]
},
"execution_count": 132,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.shape"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4.5227014967230694e-05"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"logreg = LinearRegression()\n",
"logreg.fit(X, Y)\n",
"\n",
"import pickle\n",
"with open('logreg.pkl', 'wb') as f:\n",
" pickle.dump(logreg, f)\n",
"\n",
"logreg.score(X, Y)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0:\ttest: 0.9786223\tbest: 0.9786223 (0)\ttotal: 51.1s\tremaining: 7m 39s\n",
"1:\ttest: 0.9950170\tbest: 0.9950170 (1)\ttotal: 1m 13s\tremaining: 4m 54s\n",
"2:\ttest: 0.9966407\tbest: 0.9966407 (2)\ttotal: 1m 35s\tremaining: 3m 42s\n",
"3:\ttest: 0.9982912\tbest: 0.9982912 (3)\ttotal: 1m 56s\tremaining: 2m 55s\n",
"4:\ttest: 0.9988039\tbest: 0.9988039 (4)\ttotal: 2m 18s\tremaining: 2m 18s\n",
"5:\ttest: 0.9992459\tbest: 0.9992459 (5)\ttotal: 2m 39s\tremaining: 1m 46s\n",
"6:\ttest: 0.9997030\tbest: 0.9997030 (6)\ttotal: 3m 1s\tremaining: 1m 17s\n",
"7:\ttest: 0.9998173\tbest: 0.9998173 (7)\ttotal: 3m 22s\tremaining: 50.7s\n",
"8:\ttest: 0.9998216\tbest: 0.9998216 (8)\ttotal: 3m 44s\tremaining: 24.9s\n",
"9:\ttest: 0.9998608\tbest: 0.9998608 (9)\ttotal: 4m 5s\tremaining: 0us\n",
"\n",
"bestTest = 0.9998607928\n",
"bestIteration = 9\n",
"\n"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
"\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
"\u001b[1;31mClick here for more info. \n",
"\u001b[1;31mView Jupyter log for further details."
]
}
],
"source": [
"from catboost import CatBoostRanker,Pool\n",
"from sklearn.model_selection import train_test_split\n",
"\n",
"X, X_test, Y, Y_test = train_test_split(X, Y, test_size=0.1, random_state=42)\n",
"classes_test = np.ones(len(Y_test)).astype(int)\n",
"test_pool = Pool(data=X_test, label=Y_test, group_id=classes_test)\n",
"\n",
"\n",
"classes_train = np.ones(len(Y)).astype(int)\n",
"train_pool = Pool(data=X, label=Y, group_id=classes_train,)\n",
"\n",
"\n",
"cb = CatBoostRanker(iterations=10,)\n",
"cb.fit(train_pool,eval_set=test_pool)\n",
"cb.save_model('model.cbm')\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[0.82140051]\n",
" [0.91314228]\n",
" [0.92991252]]\n"
]
}
],
"source": [
"import numpy as np\n",
"from sklearn.metrics.pairwise import cosine_similarity\n",
"\n",
"# Пример данных\n",
"matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n",
"vector = np.array([0.5, 0.7, 0.3])\n",
"\n",
"# Вычисление косинусного сходства между матрицей и вектором\n",
"similarity = cosine_similarity(matrix, vector.reshape(1, -1))\n",
"\n",
"print(similarity)\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "cv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}