{ "cells": [ { "cell_type": "code", "execution_count": 27, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "mJNjt9W69_bO", "outputId": "5b9d99cd-abc3-406d-e0be-62e90dd489a6" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/content/DATA1.xlsx\n" ] } ], "source": [ "from pandas import read_excel, concat\n", "from sklearn.model_selection import cross_val_score\n", "from sklearn.model_selection import train_test_split\n", "from sklearn.preprocessing import LabelEncoder\n", "from sklearn.model_selection import StratifiedKFold\n", "from sklearn.linear_model import SGDClassifier\n", "from sklearn.preprocessing import StandardScaler\n", "from sklearn.linear_model import RidgeClassifier\n", "from sklearn.linear_model import LogisticRegression\n", "from sklearn.neighbors import KNeighborsClassifier\n", "from sklearn.ensemble import StackingClassifier\n", "from sklearn.pipeline import Pipeline\n", "\n", "import tensorflow as tf\n", "import numpy\n", "\n", "datapath = input()\n", "df = read_excel(datapath, names = [\"OPEN\", \"HIGH\", \"LOW\", \"CLOSE\", \"VOLUME\", \"MACD\", \"TSV\", \"TRIX\", \"AROON\", \"McGINLEY\", \"ST_s\", \"ST_l\", \"RSI\", \"CMF\", \"WR\", \"ADX\", \"CMX\", \"ATR\", \"QQE\", \"AOSC\", \"STOCH\", \"SRSI\", \"ESMI\", \"RVI\", \"VOLOSC\", \"COSC\", \"KOSC\", \"class\"])\n", "X = df[[\"OPEN\", \"HIGH\", \"LOW\", \"CLOSE\", \"VOLUME\", \"MACD\", \"TSV\", \"TRIX\", \"AROON\", \"McGINLEY\", \"ST_s\", \"ST_l\", \"RSI\", \"CMF\", \"WR\", \"ADX\", \"CMX\", \"ATR\", \"QQE\", \"AOSC\", \"STOCH\", \"SRSI\", \"ESMI\", \"RVI\", \"VOLOSC\", \"COSC\", \"KOSC\"]]\n", "y = df[\"class\"]\n", "#X = X.transpose(28,)\n", "# split into input (X) and output (Y) variables\n", "X_train = X[0:20000]\n", "Y_train = y[0:20000]\n", "X_test = X[20000:]\n", "Y_test = y[20000:]" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "id": "UZo0CS2Y0-BB" }, "outputs": [], "source": [ "X_train = numpy.array(X_train)\n", "Y_train = numpy.array(Y_train)\n", "X_test = numpy.array(X_test)\n", "Y_test = numpy.array(Y_test)" ] }, { "cell_type": "code", "execution_count": 32, "metadata": { "id": "a2YyF0bD7UTU", "colab": { "base_uri": "https://localhost:8080/" }, "outputId": "06c52cac-4f0d-49fb-8bd7-ede827708efd" }, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.10/dist-packages/sklearn/decomposition/_fastica.py:542: FutureWarning: Starting in v1.3, whiten='unit-variance' will be used by default.\n", " warnings.warn(\n" ] } ], "source": [ "from sklearn.decomposition import FastICA\n", "ica = FastICA(n_components=27)\n", "#ica.fit(X_train)\n", "#X_test = ica.transform(X_test)\n", "X_test = ica.fit_transform(X_test)" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "id": "N96-RvoPxxTm", "colab": { "base_uri": "https://localhost:8080/", "height": 204 }, "outputId": "10385a04-bc29-48c7-9222-179f0a041d9e" }, "outputs": [ { "output_type": "execute_result", "data": { "text/plain": [ "StackingClassifier(estimators=[('ridge', RidgeClassifier()),\n", " ('adaboost',\n", " AdaBoostClassifier(n_estimators=27)),\n", " ('bagging',\n", " BaggingClassifier(estimator=SVC(),\n", " n_estimators=27,\n", " random_state=0)),\n", " ('extratrees',\n", " ExtraTreesClassifier(n_estimators=27,\n", " random_state=0))],\n", " final_estimator=HistGradientBoostingClassifier())" ], "text/html": [ "
StackingClassifier(estimators=[('ridge', RidgeClassifier()),\n",
              "                               ('adaboost',\n",
              "                                AdaBoostClassifier(n_estimators=27)),\n",
              "                               ('bagging',\n",
              "                                BaggingClassifier(estimator=SVC(),\n",
              "                                                  n_estimators=27,\n",
              "                                                  random_state=0)),\n",
              "                               ('extratrees',\n",
              "                                ExtraTreesClassifier(n_estimators=27,\n",
              "                                                     random_state=0))],\n",
              "                   final_estimator=HistGradientBoostingClassifier())
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
" ] }, "metadata": {}, "execution_count": 33 } ], "source": [ "from sklearn.pipeline import make_pipeline\n", "from sklearn.ensemble import GradientBoostingClassifier\n", "from sklearn.ensemble import AdaBoostClassifier\n", "from sklearn.ensemble import ExtraTreesClassifier\n", "from sklearn.ensemble import BaggingClassifier\n", "from sklearn.ensemble import HistGradientBoostingClassifier\n", "from sklearn.ensemble import IsolationForest\n", "from sklearn.svm import SVC\n", "estimators = []\n", "estimators.append(('ridge', RidgeClassifier()))\n", "estimators.append(('adaboost', AdaBoostClassifier(n_estimators=27)))\n", "estimators.append(('bagging', BaggingClassifier(estimator=SVC(), n_estimators=27, random_state=0)))\n", "estimators.append(('extratrees', ExtraTreesClassifier(n_estimators=27, random_state=0)))\n", "clf = StackingClassifier(estimators=estimators, final_estimator= HistGradientBoostingClassifier())\n", "# Fit the model/pipeline\n", "clf.fit(X_train, Y_train)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "tJpvnQi2_Ue6", "outputId": "b0ab533d-1629-4c8c-c1e0-d40588f6735a" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Mounted at /content/drive\n" ] } ], "source": [ "from google.colab import drive\n", "drive.mount('/content/drive')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "G1g-GhjS3RBh" }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 34, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "AkqE3snoLHN-", "outputId": "1c1b75c9-9169-4fea-ce0f-17ee77b5b3fe" }, "outputs": [ { "output_type": "stream", "name": "stdout", "text": [ "Accuracy: 0.5831435079726651\n" ] } ], "source": [ "from sklearn.metrics import accuracy_score\n", "predicted_classes = clf.predict(X_test)\n", "\n", "# Вычислите точность (accuracy) сравнив предсказанные классы с истинными метками\n", "accuracy = accuracy_score(predicted_classes, Y_test)\n", "\n", "print(\"Accuracy:\", accuracy)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "J0lm_9SHNO8q" }, "outputs": [], "source": [] } ], "metadata": { "accelerator": "TPU", "colab": { "provenance": [] }, "kernelspec": { "display_name": "Python 3", "name": "python3" }, "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 0 }