{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "id": "a5Vf7VhQNGDs" }, "outputs": [], "source": [ "import pandas as pd\n", "\n", "df = pd.read_csv('/content/CS279 Data - Sheet1.csv')" ] }, { "cell_type": "code", "source": [ "df = df.dropna()" ], "metadata": { "id": "TkOLhVxqNmNR" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "from sklearn.preprocessing import LabelEncoder\n", "label_encoder = LabelEncoder()\n", "df['Shape_Encoded'] = label_encoder.fit_transform(df['Shape'])\n", "df['Color_Encoded'] = label_encoder.fit_transform(df['Color'])\n", "df['Diagnosis'] = label_encoder.fit_transform(df['Infected'])" ], "metadata": { "id": "3iLH8iynNppc" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "X = df[['Area']]\n", "y = df[['Diagnosis']]" ], "metadata": { "id": "9MrbV8gdOgAR" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "from sklearn.model_selection import train_test_split\n", "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)" ], "metadata": { "id": "yKmSraTfO300" }, "execution_count": null, "outputs": [] }, { "cell_type": "code", "source": [ "from sklearn.linear_model import LogisticRegression\n", "log_reg_model = LogisticRegression(random_state=42)\n", "log_reg_model.fit(X_train, y_train)" ], "metadata": { "colab": { "base_uri": "https://localhost:8080/", "height": 136 }, "id": "pRAanHQZO--R", "outputId": "b7e6c4ae-8364-4cb7-f2c7-0495bc22058c" }, "execution_count": null, "outputs": [ { "output_type": "stream", "name": "stderr", "text": [ "/usr/local/lib/python3.10/dist-packages/sklearn/utils/validation.py:1339: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n", " y = column_or_1d(y, warn=True)\n" ] }, { "output_type": "execute_result", "data": { "text/plain": [ "LogisticRegression(random_state=42)" ], "text/html": [ "
LogisticRegression(random_state=42)In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
LogisticRegression(random_state=42)