{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "nN-xnkvdLNBY" }, "outputs": [], "source": [ "from sklearn.datasets import load_breast_cancer\n", "\n", "import warnings\n", "warnings.filterwarnings(\"ignore\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "B6ADEIzjLg0j" }, "outputs": [], "source": [ "features, target = load_breast_cancer(return_X_y=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 136 }, "colab_type": "code", "id": "d06eh05zLlQs", "outputId": "36ae4c7d-4bab-45f0-c54f-3e502bc68392" }, "outputs": [], "source": [ "print(features)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 289 }, "colab_type": "code", "id": "BE4AL0aWLtQ8", "outputId": "9fa31d1d-c463-4669-cfc7-d3eeb339cbc6" }, "outputs": [], "source": [ "print(target)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "YI5uswg-LFu7" }, "outputs": [], "source": [ "from sklearn.ensemble import RandomForestClassifier" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "xxeZg1GJL1GK" }, "outputs": [], "source": [ "seed = 888" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "PO_v8g1QL6Pl" }, "outputs": [], "source": [ "rf_model = RandomForestClassifier(random_state=seed)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 170 }, "colab_type": "code", "id": "oZXvYZnLMA1-", "outputId": "8c985441-7141-4121-d52d-d788b46065bc" }, "outputs": [], "source": [ "rf_model.fit(features, target)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "5jBaoxQiMFCK" }, "outputs": [], "source": [ "preds = rf_model.predict(features)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 289 }, "colab_type": "code", "id": "jWIYWJNQMIqo", "outputId": "5a618bc5-265f-4aed-b86b-d022ea0f55d1" }, "outputs": [], "source": [ "print(preds)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": {}, "colab_type": "code", "id": "BJFEySyvMKpo" }, "outputs": [], "source": [ "from sklearn.metrics import accuracy_score" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 34 }, "colab_type": "code", "id": "-NhTHR8XMUwW", "outputId": "096200a6-5040-4b80-8be1-5c5bf05c3caa" }, "outputs": [], "source": [ "accuracy_score(target, preds)" ] } ], "metadata": { "colab": { "collapsed_sections": [], "name": "Exercise1_03.ipynb", "provenance": [] }, "kernelspec": { "display_name": "Python 3", "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.8.6" } }, "nbformat": 4, "nbformat_minor": 1 }