{
"cells": [
{
"cell_type": "markdown",
"id": "bb00e75d",
"metadata": {},
"source": [
"# Prepare: Remove Constant Columns and Outliers"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ac4ed764",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8ed50135",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"
\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" col1 | \n",
" col2 | \n",
" col3 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1 | \n",
" 1.0 | \n",
" 1 | \n",
"
\n",
" \n",
" 1 | \n",
" 2 | \n",
" 1.0 | \n",
" 2 | \n",
"
\n",
" \n",
" 2 | \n",
" 3 | \n",
" 1.0 | \n",
" 101 | \n",
"
\n",
" \n",
" 3 | \n",
" 4 | \n",
" 1.0 | \n",
" 3 | \n",
"
\n",
" \n",
" 4 | \n",
" 5 | \n",
" 1.0 | \n",
" 4 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" col1 col2 col3\n",
"0 1 1.0 1\n",
"1 2 1.0 2\n",
"2 3 1.0 101\n",
"3 4 1.0 3\n",
"4 5 1.0 4"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df = pd.DataFrame()\n",
"df['col1'] = [1,2,3,4,5]\n",
"df['col2'] = np.ones(5)\n",
"df['col3'] = [1,2,101,3,4]\n",
"df"
]
},
{
"cell_type": "markdown",
"id": "73c64aed",
"metadata": {},
"source": [
"### Removing Constant Columns"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "95164e4f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" col1 | \n",
" col3 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1 | \n",
" 1 | \n",
"
\n",
" \n",
" 1 | \n",
" 2 | \n",
" 2 | \n",
"
\n",
" \n",
" 2 | \n",
" 3 | \n",
" 101 | \n",
"
\n",
" \n",
" 3 | \n",
" 4 | \n",
" 3 | \n",
"
\n",
" \n",
" 4 | \n",
" 5 | \n",
" 4 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" col1 col3\n",
"0 1 1\n",
"1 2 2\n",
"2 3 101\n",
"3 4 3\n",
"4 5 4"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from chemml.preprocessing import ConstantColumns, Outliers\n",
"df1 = ConstantColumns(df)\n",
"df1"
]
},
{
"cell_type": "markdown",
"id": "0f811cf0",
"metadata": {},
"source": [
"### Removing oultiers based on mean"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "82e21710",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" col1 | \n",
" col2 | \n",
" col3 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1 | \n",
" 1.0 | \n",
" 1 | \n",
"
\n",
" \n",
" 1 | \n",
" 2 | \n",
" 1.0 | \n",
" 2 | \n",
"
\n",
" \n",
" 2 | \n",
" 3 | \n",
" 1.0 | \n",
" 101 | \n",
"
\n",
" \n",
" 3 | \n",
" 4 | \n",
" 1.0 | \n",
" 3 | \n",
"
\n",
" \n",
" 4 | \n",
" 5 | \n",
" 1.0 | \n",
" 4 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" col1 col2 col3\n",
"0 1 1.0 1\n",
"1 2 1.0 2\n",
"2 3 1.0 101\n",
"3 4 1.0 3\n",
"4 5 1.0 4"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_clean = Outliers(df, m=2.0,strategy='mean')\n",
"df_clean"
]
},
{
"cell_type": "markdown",
"id": "7f5f338e",
"metadata": {},
"source": [
"### Removing outliers based on median"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "2ebb849b",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"
\n",
" \n",
" \n",
" | \n",
" col1 | \n",
" col2 | \n",
" col3 | \n",
"
\n",
" \n",
" \n",
" \n",
" 0 | \n",
" 1 | \n",
" 1.0 | \n",
" 1 | \n",
"
\n",
" \n",
" 1 | \n",
" 2 | \n",
" 1.0 | \n",
" 2 | \n",
"
\n",
" \n",
" 3 | \n",
" 4 | \n",
" 1.0 | \n",
" 3 | \n",
"
\n",
" \n",
" 4 | \n",
" 5 | \n",
" 1.0 | \n",
" 4 | \n",
"
\n",
" \n",
"
\n",
"
"
],
"text/plain": [
" col1 col2 col3\n",
"0 1 1.0 1\n",
"1 2 1.0 2\n",
"3 4 1.0 3\n",
"4 5 1.0 4"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df_clean = Outliers(df, m=2.0,strategy='median')\n",
"df_clean"
]
}
],
"metadata": {
"interpreter": {
"hash": "449e066aefa9e8d62513c10717355272508479920eef85d560c0383291a2cfea"
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.12"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}