{ "cells": [ { "cell_type": "markdown", "metadata": { "id": "EX6m-JG4-1E_" }, "source": [ "To standardize a feature means to shift all of its values so that their mean = 0 and to scale them so that their variance = 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "p3Z6ftQr_V51" }, "outputs": [], "source": [ "import pandas as pd\n", "data = pd.read_csv(\"file_pe_headers.csv\", sep =\",\")\n", "X = data.drop([\"Name\", \"Malware\"], axis=1).to_numpy()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(X.shape)\n", "print(X)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### standarize data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Next standarize x using StandardScaler instance\n", "from sklearn.preprocessing import StandardScaler" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "### standarize 1-dimension data" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# get e_lfanew\n", "data1st = X[:,16].reshape(-1, 1)\n", "print(data1st.shape)\n", "print(data1st)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "data1st_standardized = StandardScaler().fit_transform(data1st)\n", "\n", "print(data1st_standardized.shape)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(data1st_standardized)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### standarize multi-dimension data" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "id": "N1fKkOaj_2Qe" }, "outputs": [], "source": [ "X_standardized = StandardScaler().fit_transform(X)\n", "\n", "print(X_standardized.shape)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "colab": { "base_uri": "https://localhost:8080/" }, "id": "dE5vcO6kAJ4f", "outputId": "9b5eea03-73dd-4b30-e266-e275e95ca32f" }, "outputs": [], "source": [ "print(X_standardized)" ] }, { "cell_type": "markdown", "metadata": { "id": "2eB22gEeAkRt" }, "source": [ "It is important to standardize features because performance is highly sensitive to the relative scale of features." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "colab": { "name": "Standardizing data Udemy.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.8" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }