From 2b82db75ac4686611d6b4607c647a734a7e0616e Mon Sep 17 00:00:00 2001 From: Tellem <76844312+TellemHD@users.noreply.github.com> Date: Fri, 21 Jun 2024 11:55:52 +0200 Subject: [PATCH] feat: reorders parameters of RangeScaler and makes them keyword-only (#847) Closes #809 ### Summary of Changes - reorders parameters of RangeScaler and makes them keyword-only - updates a Tutorial in the Documentation --------- Co-authored-by: megalinter-bot <129584137+megalinter-bot@users.noreply.github.com> --- docs/tutorials/data_processing.ipynb | 774 +++++++++++++----- .../tabular/transformation/_range_scaler.py | 8 +- 2 files changed, 586 insertions(+), 196 deletions(-) diff --git a/docs/tutorials/data_processing.ipynb b/docs/tutorials/data_processing.ipynb index eb32d7caf..e5803137f 100644 --- a/docs/tutorials/data_processing.ipynb +++ b/docs/tutorials/data_processing.ipynb @@ -2,6 +2,9 @@ "cells": [ { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "# Data Processing\n", "\n", @@ -13,480 +16,873 @@ " All operations on a Table return a new Table. The original Table will not be changed.\n", "

\n", "" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "### Create & Load data\n", "\n", "1. Load your data into a `Table`:" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", - "source": [ - "from safeds.data.tabular.containers import Table\n", - "\n", - "titanic = Table.from_csv_file(\"data/titanic.csv\")" - ], + "execution_count": 1, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.418025600Z", "start_time": "2024-05-24T11:02:33.358365Z" - } + }, + "collapsed": false }, "outputs": [], - "execution_count": 1 + "source": [ + "from safeds.data.tabular.containers import Table\n", + "\n", + "titanic = Table.from_csv_file(\"data/titanic.csv\")" + ] }, { "cell_type": "markdown", - "source": [ - "2. Create a `Table` containing only the first 10 rows:" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "2. Create a `Table` containing only the first 10 rows:" + ] }, { "cell_type": "code", - "source": [ - "titanic_slice = titanic.slice_rows(length=10)\n", - "\n", - "titanic_slice # just to show the output" - ], + "execution_count": 2, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.426370200Z", "start_time": "2024-05-24T11:02:33.419030500Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+\n| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n| --- | --- | --- | --- | | --- | --- | --- | --- |\n| i64 | str | str | f64 | | f64 | str | str | i64 |\n+==================================================================================================+\n| 0 | Abbing, Mr. Anthony | male | 42.00000 | … | 7.55000 | null | Southampton | 0 |\n| 1 | Abbott, Master. | male | 13.00000 | … | 20.25000 | null | Southampton | 0 |\n| | Eugene Joseph | | | | | | | |\n| 2 | Abbott, Mr. Rossmore | male | 16.00000 | … | 20.25000 | null | Southampton | 0 |\n| | Edward | | | | | | | |\n| 3 | Abbott, Mrs. Stanton | female | 35.00000 | … | 20.25000 | null | Southampton | 1 |\n| | (Rosa Hun… | | | | | | | |\n| 4 | Abelseth, Miss. | female | 16.00000 | … | 7.65000 | null | Southampton | 1 |\n| | Karen Marie | | | | | | | |\n| 5 | Abelseth, Mr. Olaus | male | 25.00000 | … | 7.65000 | F G63 | Southampton | 1 |\n| | Jorgensen | | | | | | | |\n| 6 | Abelson, Mr. Samuel | male | 30.00000 | … | 24.00000 | null | Cherbourg | 0 |\n| 7 | Abelson, Mrs. Samuel | female | 28.00000 | … | 24.00000 | null | Cherbourg | 1 |\n| | (Hannah W… | | | | | | | |\n| 8 | Abrahamsson, Mr. | male | 20.00000 | … | 7.92500 | null | Southampton | 1 |\n| | Abraham Augus… | | | | | | | |\n| 9 | Abrahim, Mrs. Joseph | female | 18.00000 | … | 7.22920 | null | Cherbourg | 1 |\n| | (Sophie H… | | | | | | | |\n+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+", - "text/html": "
\nshape: (10, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64strstrf64i64i64stri64f64strstri64
0"Abbing, Mr. Anthony""male"42.000"C.A. 5547"37.55null"Southampton"0
1"Abbott, Master. Eugene Joseph""male"13.002"C.A. 2673"320.25null"Southampton"0
2"Abbott, Mr. Rossmore Edward""male"16.011"C.A. 2673"320.25null"Southampton"0
3"Abbott, Mrs. Stanton (Rosa Hun…"female"35.011"C.A. 2673"320.25null"Southampton"1
4"Abelseth, Miss. Karen Marie""female"16.000"348125"37.65null"Southampton"1
5"Abelseth, Mr. Olaus Jorgensen""male"25.000"348122"37.65"F G63""Southampton"1
6"Abelson, Mr. Samuel""male"30.010"P/PP 3381"224.0null"Cherbourg"0
7"Abelson, Mrs. Samuel (Hannah W…"female"28.010"P/PP 3381"224.0null"Cherbourg"1
8"Abrahamsson, Mr. Abraham Augus…"male"20.000"SOTON/O2 3101284"37.925null"Southampton"1
9"Abrahim, Mrs. Joseph (Sophie H…"female"18.000"2657"37.2292null"Cherbourg"1
" + "text/html": [ + "
\n", + "shape: (10, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64strstrf64i64i64stri64f64strstri64
0"Abbing, Mr. Anthony""male"42.000"C.A. 5547"37.55null"Southampton"0
1"Abbott, Master. Eugene Joseph""male"13.002"C.A. 2673"320.25null"Southampton"0
2"Abbott, Mr. Rossmore Edward""male"16.011"C.A. 2673"320.25null"Southampton"0
3"Abbott, Mrs. Stanton (Rosa Hun…"female"35.011"C.A. 2673"320.25null"Southampton"1
4"Abelseth, Miss. Karen Marie""female"16.000"348125"37.65null"Southampton"1
5"Abelseth, Mr. Olaus Jorgensen""male"25.000"348122"37.65"F G63""Southampton"1
6"Abelson, Mr. Samuel""male"30.010"P/PP 3381"224.0null"Cherbourg"0
7"Abelson, Mrs. Samuel (Hannah W…"female"28.010"P/PP 3381"224.0null"Cherbourg"1
8"Abrahamsson, Mr. Abraham Augus…"male"20.000"SOTON/O2 3101284"37.925null"Southampton"1
9"Abrahim, Mrs. Joseph (Sophie H…"female"18.000"2657"37.2292null"Cherbourg"1
" + ], + "text/plain": [ + "+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+\n", + "| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n", + "| --- | --- | --- | --- | | --- | --- | --- | --- |\n", + "| i64 | str | str | f64 | | f64 | str | str | i64 |\n", + "+==================================================================================================+\n", + "| 0 | Abbing, Mr. Anthony | male | 42.00000 | … | 7.55000 | null | Southampton | 0 |\n", + "| 1 | Abbott, Master. | male | 13.00000 | … | 20.25000 | null | Southampton | 0 |\n", + "| | Eugene Joseph | | | | | | | |\n", + "| 2 | Abbott, Mr. Rossmore | male | 16.00000 | … | 20.25000 | null | Southampton | 0 |\n", + "| | Edward | | | | | | | |\n", + "| 3 | Abbott, Mrs. Stanton | female | 35.00000 | … | 20.25000 | null | Southampton | 1 |\n", + "| | (Rosa Hun… | | | | | | | |\n", + "| 4 | Abelseth, Miss. | female | 16.00000 | … | 7.65000 | null | Southampton | 1 |\n", + "| | Karen Marie | | | | | | | |\n", + "| 5 | Abelseth, Mr. Olaus | male | 25.00000 | … | 7.65000 | F G63 | Southampton | 1 |\n", + "| | Jorgensen | | | | | | | |\n", + "| 6 | Abelson, Mr. Samuel | male | 30.00000 | … | 24.00000 | null | Cherbourg | 0 |\n", + "| 7 | Abelson, Mrs. Samuel | female | 28.00000 | … | 24.00000 | null | Cherbourg | 1 |\n", + "| | (Hannah W… | | | | | | | |\n", + "| 8 | Abrahamsson, Mr. | male | 20.00000 | … | 7.92500 | null | Southampton | 1 |\n", + "| | Abraham Augus… | | | | | | | |\n", + "| 9 | Abrahim, Mrs. Joseph | female | 18.00000 | … | 7.22920 | null | Cherbourg | 1 |\n", + "| | (Sophie H… | | | | | | | |\n", + "+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+" + ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 2 + "source": [ + "titanic_slice = titanic.slice_rows(length=10)\n", + "\n", + "titanic_slice # just to show the output" + ] }, { "cell_type": "markdown", - "source": [ - "3. Extract a `Column` from your `Table`:" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "3. Extract a `Column` from your `Table`:" + ] }, { "cell_type": "code", - "source": [ - "titanic_slice.get_column(\"name\")" - ], + "execution_count": 3, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.431877400Z", "start_time": "2024-05-24T11:02:33.426370200Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "+---------------------------------+\n| name |\n| --- |\n| str |\n+=================================+\n| Abbing, Mr. Anthony |\n| Abbott, Master. Eugene Joseph |\n| Abbott, Mr. Rossmore Edward |\n| Abbott, Mrs. Stanton (Rosa Hun… |\n| Abelseth, Miss. Karen Marie |\n| Abelseth, Mr. Olaus Jorgensen |\n| Abelson, Mr. Samuel |\n| Abelson, Mrs. Samuel (Hannah W… |\n| Abrahamsson, Mr. Abraham Augus… |\n| Abrahim, Mrs. Joseph (Sophie H… |\n+---------------------------------+", - "text/html": "
\nshape: (10,)
name
str
"Abbing, Mr. Anthony"
"Abbott, Master. Eugene Joseph"
"Abbott, Mr. Rossmore Edward"
"Abbott, Mrs. Stanton (Rosa Hun…
"Abelseth, Miss. Karen Marie"
"Abelseth, Mr. Olaus Jorgensen"
"Abelson, Mr. Samuel"
"Abelson, Mrs. Samuel (Hannah W…
"Abrahamsson, Mr. Abraham Augus…
"Abrahim, Mrs. Joseph (Sophie H…
" + "text/html": [ + "
\n", + "shape: (10,)
name
str
"Abbing, Mr. Anthony"
"Abbott, Master. Eugene Joseph"
"Abbott, Mr. Rossmore Edward"
"Abbott, Mrs. Stanton (Rosa Hun…
"Abelseth, Miss. Karen Marie"
"Abelseth, Mr. Olaus Jorgensen"
"Abelson, Mr. Samuel"
"Abelson, Mrs. Samuel (Hannah W…
"Abrahamsson, Mr. Abraham Augus…
"Abrahim, Mrs. Joseph (Sophie H…
" + ], + "text/plain": [ + "+---------------------------------+\n", + "| name |\n", + "| --- |\n", + "| str |\n", + "+=================================+\n", + "| Abbing, Mr. Anthony |\n", + "| Abbott, Master. Eugene Joseph |\n", + "| Abbott, Mr. Rossmore Edward |\n", + "| Abbott, Mrs. Stanton (Rosa Hun… |\n", + "| Abelseth, Miss. Karen Marie |\n", + "| Abelseth, Mr. Olaus Jorgensen |\n", + "| Abelson, Mr. Samuel |\n", + "| Abelson, Mrs. Samuel (Hannah W… |\n", + "| Abrahamsson, Mr. Abraham Augus… |\n", + "| Abrahim, Mrs. Joseph (Sophie H… |\n", + "+---------------------------------+" + ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 3 + "source": [ + "titanic_slice.get_column(\"name\")" + ] }, { "cell_type": "markdown", - "source": [ - "4. Combine a list of `Column`s to a `Table` (make sure the `Column`s have the same amount of rows):" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "4. Combine a list of `Column`s to a `Table` (make sure the `Column`s have the same amount of rows):" + ] }, { "cell_type": "code", - "source": [ - "Table.from_columns([\n", - " titanic_slice.get_column(\"name\"),\n", - " titanic_slice.get_column(\"age\")\n", - "])" - ], + "execution_count": 4, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.436929600Z", "start_time": "2024-05-24T11:02:33.430880700Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "+---------------------------------+----------+\n| name | age |\n| --- | --- |\n| str | f64 |\n+============================================+\n| Abbing, Mr. Anthony | 42.00000 |\n| Abbott, Master. Eugene Joseph | 13.00000 |\n| Abbott, Mr. Rossmore Edward | 16.00000 |\n| Abbott, Mrs. Stanton (Rosa Hun… | 35.00000 |\n| Abelseth, Miss. Karen Marie | 16.00000 |\n| Abelseth, Mr. Olaus Jorgensen | 25.00000 |\n| Abelson, Mr. Samuel | 30.00000 |\n| Abelson, Mrs. Samuel (Hannah W… | 28.00000 |\n| Abrahamsson, Mr. Abraham Augus… | 20.00000 |\n| Abrahim, Mrs. Joseph (Sophie H… | 18.00000 |\n+---------------------------------+----------+", - "text/html": "
\nshape: (10, 2)
nameage
strf64
"Abbing, Mr. Anthony"42.0
"Abbott, Master. Eugene Joseph"13.0
"Abbott, Mr. Rossmore Edward"16.0
"Abbott, Mrs. Stanton (Rosa Hun…35.0
"Abelseth, Miss. Karen Marie"16.0
"Abelseth, Mr. Olaus Jorgensen"25.0
"Abelson, Mr. Samuel"30.0
"Abelson, Mrs. Samuel (Hannah W…28.0
"Abrahamsson, Mr. Abraham Augus…20.0
"Abrahim, Mrs. Joseph (Sophie H…18.0
" + "text/html": [ + "
\n", + "shape: (10, 2)
nameage
strf64
"Abbing, Mr. Anthony"42.0
"Abbott, Master. Eugene Joseph"13.0
"Abbott, Mr. Rossmore Edward"16.0
"Abbott, Mrs. Stanton (Rosa Hun…35.0
"Abelseth, Miss. Karen Marie"16.0
"Abelseth, Mr. Olaus Jorgensen"25.0
"Abelson, Mr. Samuel"30.0
"Abelson, Mrs. Samuel (Hannah W…28.0
"Abrahamsson, Mr. Abraham Augus…20.0
"Abrahim, Mrs. Joseph (Sophie H…18.0
" + ], + "text/plain": [ + "+---------------------------------+----------+\n", + "| name | age |\n", + "| --- | --- |\n", + "| str | f64 |\n", + "+============================================+\n", + "| Abbing, Mr. Anthony | 42.00000 |\n", + "| Abbott, Master. Eugene Joseph | 13.00000 |\n", + "| Abbott, Mr. Rossmore Edward | 16.00000 |\n", + "| Abbott, Mrs. Stanton (Rosa Hun… | 35.00000 |\n", + "| Abelseth, Miss. Karen Marie | 16.00000 |\n", + "| Abelseth, Mr. Olaus Jorgensen | 25.00000 |\n", + "| Abelson, Mr. Samuel | 30.00000 |\n", + "| Abelson, Mrs. Samuel (Hannah W… | 28.00000 |\n", + "| Abrahamsson, Mr. Abraham Augus… | 20.00000 |\n", + "| Abrahim, Mrs. Joseph (Sophie H… | 18.00000 |\n", + "+---------------------------------+----------+" + ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 4 + "source": [ + "Table.from_columns([\n", + " titanic_slice.get_column(\"name\"),\n", + " titanic_slice.get_column(\"age\")\n", + "])" + ] }, { "cell_type": "markdown", - "source": [ - "5. Drop columns from a `Table`:" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "5. Drop columns from a `Table`:" + ] }, { "cell_type": "code", - "source": [ - "titanic_slice.remove_columns([\n", - " \"id\",\n", - " \"name\",\n", - " \"ticket\",\n", - " \"cabin\",\n", - " \"port_embarked\",\n", - " \"survived\"\n", - "])" - ], + "execution_count": 5, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.457085600Z", "start_time": "2024-05-24T11:02:33.436929600Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "+--------+----------+------------------+------------------+--------------+----------+\n| sex | age | siblings_spouses | parents_children | travel_class | fare |\n| --- | --- | --- | --- | --- | --- |\n| str | f64 | i64 | i64 | i64 | f64 |\n+===================================================================================+\n| male | 42.00000 | 0 | 0 | 3 | 7.55000 |\n| male | 13.00000 | 0 | 2 | 3 | 20.25000 |\n| male | 16.00000 | 1 | 1 | 3 | 20.25000 |\n| female | 35.00000 | 1 | 1 | 3 | 20.25000 |\n| female | 16.00000 | 0 | 0 | 3 | 7.65000 |\n| male | 25.00000 | 0 | 0 | 3 | 7.65000 |\n| male | 30.00000 | 1 | 0 | 2 | 24.00000 |\n| female | 28.00000 | 1 | 0 | 2 | 24.00000 |\n| male | 20.00000 | 0 | 0 | 3 | 7.92500 |\n| female | 18.00000 | 0 | 0 | 3 | 7.22920 |\n+--------+----------+------------------+------------------+--------------+----------+", - "text/html": "
\nshape: (10, 6)
sexagesiblings_spousesparents_childrentravel_classfare
strf64i64i64i64f64
"male"42.00037.55
"male"13.002320.25
"male"16.011320.25
"female"35.011320.25
"female"16.00037.65
"male"25.00037.65
"male"30.010224.0
"female"28.010224.0
"male"20.00037.925
"female"18.00037.2292
" + "text/html": [ + "
\n", + "shape: (10, 6)
sexagesiblings_spousesparents_childrentravel_classfare
strf64i64i64i64f64
"male"42.00037.55
"male"13.002320.25
"male"16.011320.25
"female"35.011320.25
"female"16.00037.65
"male"25.00037.65
"male"30.010224.0
"female"28.010224.0
"male"20.00037.925
"female"18.00037.2292
" + ], + "text/plain": [ + "+--------+----------+------------------+------------------+--------------+----------+\n", + "| sex | age | siblings_spouses | parents_children | travel_class | fare |\n", + "| --- | --- | --- | --- | --- | --- |\n", + "| str | f64 | i64 | i64 | i64 | f64 |\n", + "+===================================================================================+\n", + "| male | 42.00000 | 0 | 0 | 3 | 7.55000 |\n", + "| male | 13.00000 | 0 | 2 | 3 | 20.25000 |\n", + "| male | 16.00000 | 1 | 1 | 3 | 20.25000 |\n", + "| female | 35.00000 | 1 | 1 | 3 | 20.25000 |\n", + "| female | 16.00000 | 0 | 0 | 3 | 7.65000 |\n", + "| male | 25.00000 | 0 | 0 | 3 | 7.65000 |\n", + "| male | 30.00000 | 1 | 0 | 2 | 24.00000 |\n", + "| female | 28.00000 | 1 | 0 | 2 | 24.00000 |\n", + "| male | 20.00000 | 0 | 0 | 3 | 7.92500 |\n", + "| female | 18.00000 | 0 | 0 | 3 | 7.22920 |\n", + "+--------+----------+------------------+------------------+--------------+----------+" + ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 5 + "source": [ + "titanic_slice.remove_columns([\n", + " \"id\",\n", + " \"name\",\n", + " \"ticket\",\n", + " \"cabin\",\n", + " \"port_embarked\",\n", + " \"survived\"\n", + "])" + ] }, { "cell_type": "markdown", - "source": [ - "6. Keep only specified columns of a `Table`:" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "6. Keep only specified columns of a `Table`:" + ] }, { "cell_type": "code", - "source": [ - "titanic_slice.remove_columns_except([\"name\", \"survived\"])" - ], + "execution_count": 6, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.458084900Z", "start_time": "2024-05-24T11:02:33.441438800Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "+---------------------------------+----------+\n| name | survived |\n| --- | --- |\n| str | i64 |\n+============================================+\n| Abbing, Mr. Anthony | 0 |\n| Abbott, Master. Eugene Joseph | 0 |\n| Abbott, Mr. Rossmore Edward | 0 |\n| Abbott, Mrs. Stanton (Rosa Hun… | 1 |\n| Abelseth, Miss. Karen Marie | 1 |\n| Abelseth, Mr. Olaus Jorgensen | 1 |\n| Abelson, Mr. Samuel | 0 |\n| Abelson, Mrs. Samuel (Hannah W… | 1 |\n| Abrahamsson, Mr. Abraham Augus… | 1 |\n| Abrahim, Mrs. Joseph (Sophie H… | 1 |\n+---------------------------------+----------+", - "text/html": "
\nshape: (10, 2)
namesurvived
stri64
"Abbing, Mr. Anthony"0
"Abbott, Master. Eugene Joseph"0
"Abbott, Mr. Rossmore Edward"0
"Abbott, Mrs. Stanton (Rosa Hun…1
"Abelseth, Miss. Karen Marie"1
"Abelseth, Mr. Olaus Jorgensen"1
"Abelson, Mr. Samuel"0
"Abelson, Mrs. Samuel (Hannah W…1
"Abrahamsson, Mr. Abraham Augus…1
"Abrahim, Mrs. Joseph (Sophie H…1
" + "text/html": [ + "
\n", + "shape: (10, 2)
namesurvived
stri64
"Abbing, Mr. Anthony"0
"Abbott, Master. Eugene Joseph"0
"Abbott, Mr. Rossmore Edward"0
"Abbott, Mrs. Stanton (Rosa Hun…1
"Abelseth, Miss. Karen Marie"1
"Abelseth, Mr. Olaus Jorgensen"1
"Abelson, Mr. Samuel"0
"Abelson, Mrs. Samuel (Hannah W…1
"Abrahamsson, Mr. Abraham Augus…1
"Abrahim, Mrs. Joseph (Sophie H…1
" + ], + "text/plain": [ + "+---------------------------------+----------+\n", + "| name | survived |\n", + "| --- | --- |\n", + "| str | i64 |\n", + "+============================================+\n", + "| Abbing, Mr. Anthony | 0 |\n", + "| Abbott, Master. Eugene Joseph | 0 |\n", + "| Abbott, Mr. Rossmore Edward | 0 |\n", + "| Abbott, Mrs. Stanton (Rosa Hun… | 1 |\n", + "| Abelseth, Miss. Karen Marie | 1 |\n", + "| Abelseth, Mr. Olaus Jorgensen | 1 |\n", + "| Abelson, Mr. Samuel | 0 |\n", + "| Abelson, Mrs. Samuel (Hannah W… | 1 |\n", + "| Abrahamsson, Mr. Abraham Augus… | 1 |\n", + "| Abrahim, Mrs. Joseph (Sophie H… | 1 |\n", + "+---------------------------------+----------+" + ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 6 + "source": [ + "titanic_slice.remove_columns_except([\"name\", \"survived\"])" + ] }, { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "## Process data\n", "\n", "1. Filter rows with a given query:" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", - "source": [ - "titanic.remove_rows(\n", - " lambda row: row.get_value(\"age\") < 1\n", - ")" - ], + "execution_count": 7, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.502602800Z", "start_time": "2024-05-24T11:02:33.446034800Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "+------+---------------------+--------+----------+---+----------+-------+---------------+----------+\n| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n| --- | --- | --- | --- | | --- | --- | --- | --- |\n| i64 | str | str | f64 | | f64 | str | str | i64 |\n+==================================================================================================+\n| 0 | Abbing, Mr. Anthony | male | 42.00000 | … | 7.55000 | null | Southampton | 0 |\n| 1 | Abbott, Master. | male | 13.00000 | … | 20.25000 | null | Southampton | 0 |\n| | Eugene Joseph | | | | | | | |\n| 2 | Abbott, Mr. | male | 16.00000 | … | 20.25000 | null | Southampton | 0 |\n| | Rossmore Edward | | | | | | | |\n| 3 | Abbott, Mrs. | female | 35.00000 | … | 20.25000 | null | Southampton | 1 |\n| | Stanton (Rosa Hun… | | | | | | | |\n| 4 | Abelseth, Miss. | female | 16.00000 | … | 7.65000 | null | Southampton | 1 |\n| | Karen Marie | | | | | | | |\n| … | … | … | … | … | … | … | … | … |\n| 1303 | Yrois, Miss. | female | 24.00000 | … | 13.00000 | null | Southampton | 0 |\n| | Henriette ('Mrs H… | | | | | | | |\n| 1304 | Zabour, Miss. | female | 14.50000 | … | 14.45420 | null | Cherbourg | 0 |\n| | Hileni | | | | | | | |\n| 1306 | Zakarian, Mr. | male | 26.50000 | … | 7.22500 | null | Cherbourg | 0 |\n| | Mapriededer | | | | | | | |\n| 1307 | Zakarian, Mr. Ortin | male | 27.00000 | … | 7.22500 | null | Cherbourg | 0 |\n| 1308 | Zimmerman, Mr. Leo | male | 29.00000 | … | 7.87500 | null | Southampton | 0 |\n+------+---------------------+--------+----------+---+----------+-------+---------------+----------+", - "text/html": "
\nshape: (1_034, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64strstrf64i64i64stri64f64strstri64
0"Abbing, Mr. Anthony""male"42.000"C.A. 5547"37.55null"Southampton"0
1"Abbott, Master. Eugene Joseph""male"13.002"C.A. 2673"320.25null"Southampton"0
2"Abbott, Mr. Rossmore Edward""male"16.011"C.A. 2673"320.25null"Southampton"0
3"Abbott, Mrs. Stanton (Rosa Hun…"female"35.011"C.A. 2673"320.25null"Southampton"1
4"Abelseth, Miss. Karen Marie""female"16.000"348125"37.65null"Southampton"1
1303"Yrois, Miss. Henriette ('Mrs H…"female"24.000"248747"213.0null"Southampton"0
1304"Zabour, Miss. Hileni""female"14.510"2665"314.4542null"Cherbourg"0
1306"Zakarian, Mr. Mapriededer""male"26.500"2656"37.225null"Cherbourg"0
1307"Zakarian, Mr. Ortin""male"27.000"2670"37.225null"Cherbourg"0
1308"Zimmerman, Mr. Leo""male"29.000"315082"37.875null"Southampton"0
" + "text/html": [ + "
\n", + "shape: (1_034, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64strstrf64i64i64stri64f64strstri64
0"Abbing, Mr. Anthony""male"42.000"C.A. 5547"37.55null"Southampton"0
1"Abbott, Master. Eugene Joseph""male"13.002"C.A. 2673"320.25null"Southampton"0
2"Abbott, Mr. Rossmore Edward""male"16.011"C.A. 2673"320.25null"Southampton"0
3"Abbott, Mrs. Stanton (Rosa Hun…"female"35.011"C.A. 2673"320.25null"Southampton"1
4"Abelseth, Miss. Karen Marie""female"16.000"348125"37.65null"Southampton"1
1303"Yrois, Miss. Henriette ('Mrs H…"female"24.000"248747"213.0null"Southampton"0
1304"Zabour, Miss. Hileni""female"14.510"2665"314.4542null"Cherbourg"0
1306"Zakarian, Mr. Mapriededer""male"26.500"2656"37.225null"Cherbourg"0
1307"Zakarian, Mr. Ortin""male"27.000"2670"37.225null"Cherbourg"0
1308"Zimmerman, Mr. Leo""male"29.000"315082"37.875null"Southampton"0
" + ], + "text/plain": [ + "+------+---------------------+--------+----------+---+----------+-------+---------------+----------+\n", + "| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n", + "| --- | --- | --- | --- | | --- | --- | --- | --- |\n", + "| i64 | str | str | f64 | | f64 | str | str | i64 |\n", + "+==================================================================================================+\n", + "| 0 | Abbing, Mr. Anthony | male | 42.00000 | … | 7.55000 | null | Southampton | 0 |\n", + "| 1 | Abbott, Master. | male | 13.00000 | … | 20.25000 | null | Southampton | 0 |\n", + "| | Eugene Joseph | | | | | | | |\n", + "| 2 | Abbott, Mr. | male | 16.00000 | … | 20.25000 | null | Southampton | 0 |\n", + "| | Rossmore Edward | | | | | | | |\n", + "| 3 | Abbott, Mrs. | female | 35.00000 | … | 20.25000 | null | Southampton | 1 |\n", + "| | Stanton (Rosa Hun… | | | | | | | |\n", + "| 4 | Abelseth, Miss. | female | 16.00000 | … | 7.65000 | null | Southampton | 1 |\n", + "| | Karen Marie | | | | | | | |\n", + "| … | … | … | … | … | … | … | … | … |\n", + "| 1303 | Yrois, Miss. | female | 24.00000 | … | 13.00000 | null | Southampton | 0 |\n", + "| | Henriette ('Mrs H… | | | | | | | |\n", + "| 1304 | Zabour, Miss. | female | 14.50000 | … | 14.45420 | null | Cherbourg | 0 |\n", + "| | Hileni | | | | | | | |\n", + "| 1306 | Zakarian, Mr. | male | 26.50000 | … | 7.22500 | null | Cherbourg | 0 |\n", + "| | Mapriededer | | | | | | | |\n", + "| 1307 | Zakarian, Mr. Ortin | male | 27.00000 | … | 7.22500 | null | Cherbourg | 0 |\n", + "| 1308 | Zimmerman, Mr. Leo | male | 29.00000 | … | 7.87500 | null | Southampton | 0 |\n", + "+------+---------------------+--------+----------+---+----------+-------+---------------+----------+" + ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 7 + "source": [ + "titanic.remove_rows(\n", + " lambda row: row.get_value(\"age\") < 1\n", + ")" + ] }, { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "## Transform table\n", "1. Transform table using `Imputer`. `Imputer`s replace missing values with other values (e.g. a constant, the mean or the median of the column etc.) depending on the chosen startegy, for example, the following `Imputer` will replace missing values in the given columns of the table with the constant 0:" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", - "source": [ - "from safeds.data.tabular.transformation import SimpleImputer\n", - "\n", - "imputer = SimpleImputer(SimpleImputer.Strategy.constant(0), column_names=[\"age\", \"fare\", \"cabin\", \"port_embarked\"]).fit(titanic)\n", - "imputer.transform(titanic_slice)" - ], + "execution_count": 8, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.520628800Z", "start_time": "2024-05-24T11:02:33.453086900Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+\n| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n| --- | --- | --- | --- | | --- | --- | --- | --- |\n| i64 | str | str | f64 | | f64 | str | str | i64 |\n+==================================================================================================+\n| 0 | Abbing, Mr. Anthony | male | 42.00000 | … | 7.55000 | 0 | Southampton | 0 |\n| 1 | Abbott, Master. | male | 13.00000 | … | 20.25000 | 0 | Southampton | 0 |\n| | Eugene Joseph | | | | | | | |\n| 2 | Abbott, Mr. Rossmore | male | 16.00000 | … | 20.25000 | 0 | Southampton | 0 |\n| | Edward | | | | | | | |\n| 3 | Abbott, Mrs. Stanton | female | 35.00000 | … | 20.25000 | 0 | Southampton | 1 |\n| | (Rosa Hun… | | | | | | | |\n| 4 | Abelseth, Miss. | female | 16.00000 | … | 7.65000 | 0 | Southampton | 1 |\n| | Karen Marie | | | | | | | |\n| 5 | Abelseth, Mr. Olaus | male | 25.00000 | … | 7.65000 | F G63 | Southampton | 1 |\n| | Jorgensen | | | | | | | |\n| 6 | Abelson, Mr. Samuel | male | 30.00000 | … | 24.00000 | 0 | Cherbourg | 0 |\n| 7 | Abelson, Mrs. Samuel | female | 28.00000 | … | 24.00000 | 0 | Cherbourg | 1 |\n| | (Hannah W… | | | | | | | |\n| 8 | Abrahamsson, Mr. | male | 20.00000 | … | 7.92500 | 0 | Southampton | 1 |\n| | Abraham Augus… | | | | | | | |\n| 9 | Abrahim, Mrs. Joseph | female | 18.00000 | … | 7.22920 | 0 | Cherbourg | 1 |\n| | (Sophie H… | | | | | | | |\n+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+", - "text/html": "
\nshape: (10, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64strstrf64i64i64stri64f64strstri64
0"Abbing, Mr. Anthony""male"42.000"C.A. 5547"37.55"0""Southampton"0
1"Abbott, Master. Eugene Joseph""male"13.002"C.A. 2673"320.25"0""Southampton"0
2"Abbott, Mr. Rossmore Edward""male"16.011"C.A. 2673"320.25"0""Southampton"0
3"Abbott, Mrs. Stanton (Rosa Hun…"female"35.011"C.A. 2673"320.25"0""Southampton"1
4"Abelseth, Miss. Karen Marie""female"16.000"348125"37.65"0""Southampton"1
5"Abelseth, Mr. Olaus Jorgensen""male"25.000"348122"37.65"F G63""Southampton"1
6"Abelson, Mr. Samuel""male"30.010"P/PP 3381"224.0"0""Cherbourg"0
7"Abelson, Mrs. Samuel (Hannah W…"female"28.010"P/PP 3381"224.0"0""Cherbourg"1
8"Abrahamsson, Mr. Abraham Augus…"male"20.000"SOTON/O2 3101284"37.925"0""Southampton"1
9"Abrahim, Mrs. Joseph (Sophie H…"female"18.000"2657"37.2292"0""Cherbourg"1
" + "text/html": [ + "
\n", + "shape: (10, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64strstrf64i64i64stri64f64strstri64
0"Abbing, Mr. Anthony""male"42.000"C.A. 5547"37.55"0""Southampton"0
1"Abbott, Master. Eugene Joseph""male"13.002"C.A. 2673"320.25"0""Southampton"0
2"Abbott, Mr. Rossmore Edward""male"16.011"C.A. 2673"320.25"0""Southampton"0
3"Abbott, Mrs. Stanton (Rosa Hun…"female"35.011"C.A. 2673"320.25"0""Southampton"1
4"Abelseth, Miss. Karen Marie""female"16.000"348125"37.65"0""Southampton"1
5"Abelseth, Mr. Olaus Jorgensen""male"25.000"348122"37.65"F G63""Southampton"1
6"Abelson, Mr. Samuel""male"30.010"P/PP 3381"224.0"0""Cherbourg"0
7"Abelson, Mrs. Samuel (Hannah W…"female"28.010"P/PP 3381"224.0"0""Cherbourg"1
8"Abrahamsson, Mr. Abraham Augus…"male"20.000"SOTON/O2 3101284"37.925"0""Southampton"1
9"Abrahim, Mrs. Joseph (Sophie H…"female"18.000"2657"37.2292"0""Cherbourg"1
" + ], + "text/plain": [ + "+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+\n", + "| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n", + "| --- | --- | --- | --- | | --- | --- | --- | --- |\n", + "| i64 | str | str | f64 | | f64 | str | str | i64 |\n", + "+==================================================================================================+\n", + "| 0 | Abbing, Mr. Anthony | male | 42.00000 | … | 7.55000 | 0 | Southampton | 0 |\n", + "| 1 | Abbott, Master. | male | 13.00000 | … | 20.25000 | 0 | Southampton | 0 |\n", + "| | Eugene Joseph | | | | | | | |\n", + "| 2 | Abbott, Mr. Rossmore | male | 16.00000 | … | 20.25000 | 0 | Southampton | 0 |\n", + "| | Edward | | | | | | | |\n", + "| 3 | Abbott, Mrs. Stanton | female | 35.00000 | … | 20.25000 | 0 | Southampton | 1 |\n", + "| | (Rosa Hun… | | | | | | | |\n", + "| 4 | Abelseth, Miss. | female | 16.00000 | … | 7.65000 | 0 | Southampton | 1 |\n", + "| | Karen Marie | | | | | | | |\n", + "| 5 | Abelseth, Mr. Olaus | male | 25.00000 | … | 7.65000 | F G63 | Southampton | 1 |\n", + "| | Jorgensen | | | | | | | |\n", + "| 6 | Abelson, Mr. Samuel | male | 30.00000 | … | 24.00000 | 0 | Cherbourg | 0 |\n", + "| 7 | Abelson, Mrs. Samuel | female | 28.00000 | … | 24.00000 | 0 | Cherbourg | 1 |\n", + "| | (Hannah W… | | | | | | | |\n", + "| 8 | Abrahamsson, Mr. | male | 20.00000 | … | 7.92500 | 0 | Southampton | 1 |\n", + "| | Abraham Augus… | | | | | | | |\n", + "| 9 | Abrahim, Mrs. Joseph | female | 18.00000 | … | 7.22920 | 0 | Cherbourg | 1 |\n", + "| | (Sophie H… | | | | | | | |\n", + "+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+" + ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 8 + "source": [ + "from safeds.data.tabular.transformation import SimpleImputer\n", + "\n", + "imputer = SimpleImputer(SimpleImputer.Strategy.constant(0), column_names=[\"age\", \"fare\", \"cabin\", \"port_embarked\"]).fit(titanic)\n", + "imputer.transform(titanic_slice)" + ] }, { "cell_type": "markdown", - "source": [ - "2. Transform table using `LabelEncoder`, this will encode categorical features in the chosen `Column`s as integers:" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "2. Transform table using `LabelEncoder`, this will encode categorical features in the chosen `Column`s as integers:" + ] }, { "cell_type": "code", - "source": [ - "from safeds.data.tabular.transformation import LabelEncoder\n", - "\n", - "encoder = LabelEncoder(column_names=[\"sex\", \"port_embarked\"]).fit(titanic)\n", - "encoder.transform(titanic_slice)" - ], + "execution_count": 9, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.584654300Z", "start_time": "2024-05-24T11:02:33.461597400Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "+-----+-------------------------+-----+----------+---+----------+-------+---------------+----------+\n| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n| --- | --- | --- | --- | | --- | --- | --- | --- |\n| i64 | str | u32 | f64 | | f64 | str | u32 | i64 |\n+==================================================================================================+\n| 0 | Abbing, Mr. Anthony | 0 | 42.00000 | … | 7.55000 | null | 0 | 0 |\n| 1 | Abbott, Master. Eugene | 0 | 13.00000 | … | 20.25000 | null | 0 | 0 |\n| | Joseph | | | | | | | |\n| 2 | Abbott, Mr. Rossmore | 0 | 16.00000 | … | 20.25000 | null | 0 | 0 |\n| | Edward | | | | | | | |\n| 3 | Abbott, Mrs. Stanton | 1 | 35.00000 | … | 20.25000 | null | 0 | 1 |\n| | (Rosa Hun… | | | | | | | |\n| 4 | Abelseth, Miss. Karen | 1 | 16.00000 | … | 7.65000 | null | 0 | 1 |\n| | Marie | | | | | | | |\n| 5 | Abelseth, Mr. Olaus | 0 | 25.00000 | … | 7.65000 | F G63 | 0 | 1 |\n| | Jorgensen | | | | | | | |\n| 6 | Abelson, Mr. Samuel | 0 | 30.00000 | … | 24.00000 | null | 1 | 0 |\n| 7 | Abelson, Mrs. Samuel | 1 | 28.00000 | … | 24.00000 | null | 1 | 1 |\n| | (Hannah W… | | | | | | | |\n| 8 | Abrahamsson, Mr. | 0 | 20.00000 | … | 7.92500 | null | 0 | 1 |\n| | Abraham Augus… | | | | | | | |\n| 9 | Abrahim, Mrs. Joseph | 1 | 18.00000 | … | 7.22920 | null | 1 | 1 |\n| | (Sophie H… | | | | | | | |\n+-----+-------------------------+-----+----------+---+----------+-------+---------------+----------+", - "text/html": "
\nshape: (10, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64stru32f64i64i64stri64f64stru32i64
0"Abbing, Mr. Anthony"042.000"C.A. 5547"37.55null00
1"Abbott, Master. Eugene Joseph"013.002"C.A. 2673"320.25null00
2"Abbott, Mr. Rossmore Edward"016.011"C.A. 2673"320.25null00
3"Abbott, Mrs. Stanton (Rosa Hun…135.011"C.A. 2673"320.25null01
4"Abelseth, Miss. Karen Marie"116.000"348125"37.65null01
5"Abelseth, Mr. Olaus Jorgensen"025.000"348122"37.65"F G63"01
6"Abelson, Mr. Samuel"030.010"P/PP 3381"224.0null10
7"Abelson, Mrs. Samuel (Hannah W…128.010"P/PP 3381"224.0null11
8"Abrahamsson, Mr. Abraham Augus…020.000"SOTON/O2 3101284"37.925null01
9"Abrahim, Mrs. Joseph (Sophie H…118.000"2657"37.2292null11
" + "text/html": [ + "
\n", + "shape: (10, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64stru32f64i64i64stri64f64stru32i64
0"Abbing, Mr. Anthony"042.000"C.A. 5547"37.55null00
1"Abbott, Master. Eugene Joseph"013.002"C.A. 2673"320.25null00
2"Abbott, Mr. Rossmore Edward"016.011"C.A. 2673"320.25null00
3"Abbott, Mrs. Stanton (Rosa Hun…135.011"C.A. 2673"320.25null01
4"Abelseth, Miss. Karen Marie"116.000"348125"37.65null01
5"Abelseth, Mr. Olaus Jorgensen"025.000"348122"37.65"F G63"01
6"Abelson, Mr. Samuel"030.010"P/PP 3381"224.0null10
7"Abelson, Mrs. Samuel (Hannah W…128.010"P/PP 3381"224.0null11
8"Abrahamsson, Mr. Abraham Augus…020.000"SOTON/O2 3101284"37.925null01
9"Abrahim, Mrs. Joseph (Sophie H…118.000"2657"37.2292null11
" + ], + "text/plain": [ + "+-----+-------------------------+-----+----------+---+----------+-------+---------------+----------+\n", + "| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n", + "| --- | --- | --- | --- | | --- | --- | --- | --- |\n", + "| i64 | str | u32 | f64 | | f64 | str | u32 | i64 |\n", + "+==================================================================================================+\n", + "| 0 | Abbing, Mr. Anthony | 0 | 42.00000 | … | 7.55000 | null | 0 | 0 |\n", + "| 1 | Abbott, Master. Eugene | 0 | 13.00000 | … | 20.25000 | null | 0 | 0 |\n", + "| | Joseph | | | | | | | |\n", + "| 2 | Abbott, Mr. Rossmore | 0 | 16.00000 | … | 20.25000 | null | 0 | 0 |\n", + "| | Edward | | | | | | | |\n", + "| 3 | Abbott, Mrs. Stanton | 1 | 35.00000 | … | 20.25000 | null | 0 | 1 |\n", + "| | (Rosa Hun… | | | | | | | |\n", + "| 4 | Abelseth, Miss. Karen | 1 | 16.00000 | … | 7.65000 | null | 0 | 1 |\n", + "| | Marie | | | | | | | |\n", + "| 5 | Abelseth, Mr. Olaus | 0 | 25.00000 | … | 7.65000 | F G63 | 0 | 1 |\n", + "| | Jorgensen | | | | | | | |\n", + "| 6 | Abelson, Mr. Samuel | 0 | 30.00000 | … | 24.00000 | null | 1 | 0 |\n", + "| 7 | Abelson, Mrs. Samuel | 1 | 28.00000 | … | 24.00000 | null | 1 | 1 |\n", + "| | (Hannah W… | | | | | | | |\n", + "| 8 | Abrahamsson, Mr. | 0 | 20.00000 | … | 7.92500 | null | 0 | 1 |\n", + "| | Abraham Augus… | | | | | | | |\n", + "| 9 | Abrahim, Mrs. Joseph | 1 | 18.00000 | … | 7.22920 | null | 1 | 1 |\n", + "| | (Sophie H… | | | | | | | |\n", + "+-----+-------------------------+-----+----------+---+----------+-------+---------------+----------+" + ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 9 + "source": [ + "from safeds.data.tabular.transformation import LabelEncoder\n", + "\n", + "encoder = LabelEncoder(column_names=[\"sex\", \"port_embarked\"]).fit(titanic)\n", + "encoder.transform(titanic_slice)" + ] }, { "cell_type": "markdown", - "source": [ - "3. Transform table using `OneHotEncoder`, this will create new `Column`s based on unique values in each chosen `Column`:\n" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "3. Transform table using `OneHotEncoder`, this will create new `Column`s based on unique values in each chosen `Column`:\n" + ] }, { "cell_type": "code", - "source": [ - "from safeds.data.tabular.transformation import OneHotEncoder\n", - "\n", - "encoder = OneHotEncoder(column_names=[\"sex\", \"port_embarked\"]).fit(titanic)\n", - "encoder.transform(titanic_slice)" - ], + "execution_count": 10, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.597162600Z", "start_time": "2024-05-24T11:02:33.472105400Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "+-----+------------+----------+------------+---+------------+------------+------------+------------+\n| id | name | age | siblings_s | … | sex__femal | port_embar | port_embar | port_embar |\n| --- | --- | --- | pouses | | e | ked__South | ked__Cherb | ked__Queen |\n| i64 | str | f64 | --- | | --- | ampton | ourg | stown |\n| | | | i64 | | u8 | --- | --- | --- |\n| | | | | | | u8 | u8 | u8 |\n+==================================================================================================+\n| 0 | Abbing, | 42.00000 | 0 | … | 0 | 1 | 0 | 0 |\n| | Mr. | | | | | | | |\n| | Anthony | | | | | | | |\n| 1 | Abbott, | 13.00000 | 0 | … | 0 | 1 | 0 | 0 |\n| | Master. | | | | | | | |\n| | Eugene | | | | | | | |\n| | Joseph | | | | | | | |\n| 2 | Abbott, | 16.00000 | 1 | … | 0 | 1 | 0 | 0 |\n| | Mr. | | | | | | | |\n| | Rossmore | | | | | | | |\n| | Edward | | | | | | | |\n| 3 | Abbott, | 35.00000 | 1 | … | 1 | 1 | 0 | 0 |\n| | Mrs. | | | | | | | |\n| | Stanton | | | | | | | |\n| | (Rosa Hun… | | | | | | | |\n| 4 | Abelseth, | 16.00000 | 0 | … | 1 | 1 | 0 | 0 |\n| | Miss. | | | | | | | |\n| | Karen | | | | | | | |\n| | Marie | | | | | | | |\n| 5 | Abelseth, | 25.00000 | 0 | … | 0 | 1 | 0 | 0 |\n| | Mr. Olaus | | | | | | | |\n| | Jorgensen | | | | | | | |\n| 6 | Abelson, | 30.00000 | 1 | … | 0 | 0 | 1 | 0 |\n| | Mr. Samuel | | | | | | | |\n| 7 | Abelson, | 28.00000 | 1 | … | 1 | 0 | 1 | 0 |\n| | Mrs. | | | | | | | |\n| | Samuel | | | | | | | |\n| | (Hannah W… | | | | | | | |\n| 8 | Abrahamsso | 20.00000 | 0 | … | 0 | 1 | 0 | 0 |\n| | n, Mr. | | | | | | | |\n| | Abraham | | | | | | | |\n| | Augus… | | | | | | | |\n| 9 | Abrahim, | 18.00000 | 0 | … | 1 | 0 | 1 | 0 |\n| | Mrs. | | | | | | | |\n| | Joseph | | | | | | | |\n| | (Sophie H… | | | | | | | |\n+-----+------------+----------+------------+---+------------+------------+------------+------------+", - "text/html": "
\nshape: (10, 15)
idnameagesiblings_spousesparents_childrentickettravel_classfarecabinsurvivedsex__malesex__femaleport_embarked__Southamptonport_embarked__Cherbourgport_embarked__Queenstown
i64strf64i64i64stri64f64stri64u8u8u8u8u8
0"Abbing, Mr. Anthony"42.000"C.A. 5547"37.55null010100
1"Abbott, Master. Eugene Joseph"13.002"C.A. 2673"320.25null010100
2"Abbott, Mr. Rossmore Edward"16.011"C.A. 2673"320.25null010100
3"Abbott, Mrs. Stanton (Rosa Hun…35.011"C.A. 2673"320.25null101100
4"Abelseth, Miss. Karen Marie"16.000"348125"37.65null101100
5"Abelseth, Mr. Olaus Jorgensen"25.000"348122"37.65"F G63"110100
6"Abelson, Mr. Samuel"30.010"P/PP 3381"224.0null010010
7"Abelson, Mrs. Samuel (Hannah W…28.010"P/PP 3381"224.0null101010
8"Abrahamsson, Mr. Abraham Augus…20.000"SOTON/O2 3101284"37.925null110100
9"Abrahim, Mrs. Joseph (Sophie H…18.000"2657"37.2292null101010
" + "text/html": [ + "
\n", + "shape: (10, 15)
idnameagesiblings_spousesparents_childrentickettravel_classfarecabinsurvivedsex__malesex__femaleport_embarked__Southamptonport_embarked__Cherbourgport_embarked__Queenstown
i64strf64i64i64stri64f64stri64u8u8u8u8u8
0"Abbing, Mr. Anthony"42.000"C.A. 5547"37.55null010100
1"Abbott, Master. Eugene Joseph"13.002"C.A. 2673"320.25null010100
2"Abbott, Mr. Rossmore Edward"16.011"C.A. 2673"320.25null010100
3"Abbott, Mrs. Stanton (Rosa Hun…35.011"C.A. 2673"320.25null101100
4"Abelseth, Miss. Karen Marie"16.000"348125"37.65null101100
5"Abelseth, Mr. Olaus Jorgensen"25.000"348122"37.65"F G63"110100
6"Abelson, Mr. Samuel"30.010"P/PP 3381"224.0null010010
7"Abelson, Mrs. Samuel (Hannah W…28.010"P/PP 3381"224.0null101010
8"Abrahamsson, Mr. Abraham Augus…20.000"SOTON/O2 3101284"37.925null110100
9"Abrahim, Mrs. Joseph (Sophie H…18.000"2657"37.2292null101010
" + ], + "text/plain": [ + "+-----+------------+----------+------------+---+------------+------------+------------+------------+\n", + "| id | name | age | siblings_s | … | sex__femal | port_embar | port_embar | port_embar |\n", + "| --- | --- | --- | pouses | | e | ked__South | ked__Cherb | ked__Queen |\n", + "| i64 | str | f64 | --- | | --- | ampton | ourg | stown |\n", + "| | | | i64 | | u8 | --- | --- | --- |\n", + "| | | | | | | u8 | u8 | u8 |\n", + "+==================================================================================================+\n", + "| 0 | Abbing, | 42.00000 | 0 | … | 0 | 1 | 0 | 0 |\n", + "| | Mr. | | | | | | | |\n", + "| | Anthony | | | | | | | |\n", + "| 1 | Abbott, | 13.00000 | 0 | … | 0 | 1 | 0 | 0 |\n", + "| | Master. | | | | | | | |\n", + "| | Eugene | | | | | | | |\n", + "| | Joseph | | | | | | | |\n", + "| 2 | Abbott, | 16.00000 | 1 | … | 0 | 1 | 0 | 0 |\n", + "| | Mr. | | | | | | | |\n", + "| | Rossmore | | | | | | | |\n", + "| | Edward | | | | | | | |\n", + "| 3 | Abbott, | 35.00000 | 1 | … | 1 | 1 | 0 | 0 |\n", + "| | Mrs. | | | | | | | |\n", + "| | Stanton | | | | | | | |\n", + "| | (Rosa Hun… | | | | | | | |\n", + "| 4 | Abelseth, | 16.00000 | 0 | … | 1 | 1 | 0 | 0 |\n", + "| | Miss. | | | | | | | |\n", + "| | Karen | | | | | | | |\n", + "| | Marie | | | | | | | |\n", + "| 5 | Abelseth, | 25.00000 | 0 | … | 0 | 1 | 0 | 0 |\n", + "| | Mr. Olaus | | | | | | | |\n", + "| | Jorgensen | | | | | | | |\n", + "| 6 | Abelson, | 30.00000 | 1 | … | 0 | 0 | 1 | 0 |\n", + "| | Mr. Samuel | | | | | | | |\n", + "| 7 | Abelson, | 28.00000 | 1 | … | 1 | 0 | 1 | 0 |\n", + "| | Mrs. | | | | | | | |\n", + "| | Samuel | | | | | | | |\n", + "| | (Hannah W… | | | | | | | |\n", + "| 8 | Abrahamsso | 20.00000 | 0 | … | 0 | 1 | 0 | 0 |\n", + "| | n, Mr. | | | | | | | |\n", + "| | Abraham | | | | | | | |\n", + "| | Augus… | | | | | | | |\n", + "| 9 | Abrahim, | 18.00000 | 0 | … | 1 | 0 | 1 | 0 |\n", + "| | Mrs. | | | | | | | |\n", + "| | Joseph | | | | | | | |\n", + "| | (Sophie H… | | | | | | | |\n", + "+-----+------------+----------+------------+---+------------+------------+------------+------------+" + ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 10 + "source": [ + "from safeds.data.tabular.transformation import OneHotEncoder\n", + "\n", + "encoder = OneHotEncoder(column_names=[\"sex\", \"port_embarked\"]).fit(titanic)\n", + "encoder.transform(titanic_slice)" + ] }, { "cell_type": "markdown", - "source": [ - " 4. Transform table using `RangeScaler`, this will scale the values in the chosen `Column`s to a given range:" - ], "metadata": { "collapsed": false - } + }, + "source": [ + " 4. Transform table using `RangeScaler`, this will scale the values in the chosen `Column`s to a given range:" + ] }, { "cell_type": "code", - "source": [ - "from safeds.data.tabular.transformation import RangeScaler\n", - "\n", - "scaler = RangeScaler(0.0, 1.0, column_names=\"age\").fit(titanic)\n", - "scaler.transform(titanic_slice)" - ], + "execution_count": 11, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.599165800Z", "start_time": "2024-05-24T11:02:33.479893800Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "+-----+-----------------------+--------+---------+---+----------+-------+---------------+----------+\n| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n| --- | --- | --- | --- | | --- | --- | --- | --- |\n| i64 | str | str | f64 | | f64 | str | str | i64 |\n+==================================================================================================+\n| 0 | Abbing, Mr. Anthony | male | 0.52401 | … | 7.55000 | null | Southampton | 0 |\n| 1 | Abbott, Master. | male | 0.16075 | … | 20.25000 | null | Southampton | 0 |\n| | Eugene Joseph | | | | | | | |\n| 2 | Abbott, Mr. Rossmore | male | 0.19833 | … | 20.25000 | null | Southampton | 0 |\n| | Edward | | | | | | | |\n| 3 | Abbott, Mrs. Stanton | female | 0.43633 | … | 20.25000 | null | Southampton | 1 |\n| | (Rosa Hun… | | | | | | | |\n| 4 | Abelseth, Miss. Karen | female | 0.19833 | … | 7.65000 | null | Southampton | 1 |\n| | Marie | | | | | | | |\n| 5 | Abelseth, Mr. Olaus | male | 0.31106 | … | 7.65000 | F G63 | Southampton | 1 |\n| | Jorgensen | | | | | | | |\n| 6 | Abelson, Mr. Samuel | male | 0.37369 | … | 24.00000 | null | Cherbourg | 0 |\n| 7 | Abelson, Mrs. Samuel | female | 0.34864 | … | 24.00000 | null | Cherbourg | 1 |\n| | (Hannah W… | | | | | | | |\n| 8 | Abrahamsson, Mr. | male | 0.24843 | … | 7.92500 | null | Southampton | 1 |\n| | Abraham Augus… | | | | | | | |\n| 9 | Abrahim, Mrs. Joseph | female | 0.22338 | … | 7.22920 | null | Cherbourg | 1 |\n| | (Sophie H… | | | | | | | |\n+-----+-----------------------+--------+---------+---+----------+-------+---------------+----------+", - "text/html": "
\nshape: (10, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64strstrf64i64i64stri64f64strstri64
0"Abbing, Mr. Anthony""male"0.52400800"C.A. 5547"37.55null"Southampton"0
1"Abbott, Master. Eugene Joseph""male"0.16075102"C.A. 2673"320.25null"Southampton"0
2"Abbott, Mr. Rossmore Edward""male"0.1983311"C.A. 2673"320.25null"Southampton"0
3"Abbott, Mrs. Stanton (Rosa Hun…"female"0.43632511"C.A. 2673"320.25null"Southampton"1
4"Abelseth, Miss. Karen Marie""female"0.1983300"348125"37.65null"Southampton"1
5"Abelseth, Mr. Olaus Jorgensen""male"0.31106400"348122"37.65"F G63""Southampton"1
6"Abelson, Mr. Samuel""male"0.37369510"P/PP 3381"224.0null"Cherbourg"0
7"Abelson, Mrs. Samuel (Hannah W…"female"0.34864310"P/PP 3381"224.0null"Cherbourg"1
8"Abrahamsson, Mr. Abraham Augus…"male"0.24843400"SOTON/O2 3101284"37.925null"Southampton"1
9"Abrahim, Mrs. Joseph (Sophie H…"female"0.22338200"2657"37.2292null"Cherbourg"1
" + "text/html": [ + "
\n", + "shape: (10, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64strstrf64i64i64stri64f64strstri64
0"Abbing, Mr. Anthony""male"0.52400800"C.A. 5547"37.55null"Southampton"0
1"Abbott, Master. Eugene Joseph""male"0.16075102"C.A. 2673"320.25null"Southampton"0
2"Abbott, Mr. Rossmore Edward""male"0.1983311"C.A. 2673"320.25null"Southampton"0
3"Abbott, Mrs. Stanton (Rosa Hun…"female"0.43632511"C.A. 2673"320.25null"Southampton"1
4"Abelseth, Miss. Karen Marie""female"0.1983300"348125"37.65null"Southampton"1
5"Abelseth, Mr. Olaus Jorgensen""male"0.31106400"348122"37.65"F G63""Southampton"1
6"Abelson, Mr. Samuel""male"0.37369510"P/PP 3381"224.0null"Cherbourg"0
7"Abelson, Mrs. Samuel (Hannah W…"female"0.34864310"P/PP 3381"224.0null"Cherbourg"1
8"Abrahamsson, Mr. Abraham Augus…"male"0.24843400"SOTON/O2 3101284"37.925null"Southampton"1
9"Abrahim, Mrs. Joseph (Sophie H…"female"0.22338200"2657"37.2292null"Cherbourg"1
" + ], + "text/plain": [ + "+-----+-----------------------+--------+---------+---+----------+-------+---------------+----------+\n", + "| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n", + "| --- | --- | --- | --- | | --- | --- | --- | --- |\n", + "| i64 | str | str | f64 | | f64 | str | str | i64 |\n", + "+==================================================================================================+\n", + "| 0 | Abbing, Mr. Anthony | male | 0.52401 | … | 7.55000 | null | Southampton | 0 |\n", + "| 1 | Abbott, Master. | male | 0.16075 | … | 20.25000 | null | Southampton | 0 |\n", + "| | Eugene Joseph | | | | | | | |\n", + "| 2 | Abbott, Mr. Rossmore | male | 0.19833 | … | 20.25000 | null | Southampton | 0 |\n", + "| | Edward | | | | | | | |\n", + "| 3 | Abbott, Mrs. Stanton | female | 0.43633 | … | 20.25000 | null | Southampton | 1 |\n", + "| | (Rosa Hun… | | | | | | | |\n", + "| 4 | Abelseth, Miss. Karen | female | 0.19833 | … | 7.65000 | null | Southampton | 1 |\n", + "| | Marie | | | | | | | |\n", + "| 5 | Abelseth, Mr. Olaus | male | 0.31106 | … | 7.65000 | F G63 | Southampton | 1 |\n", + "| | Jorgensen | | | | | | | |\n", + "| 6 | Abelson, Mr. Samuel | male | 0.37369 | … | 24.00000 | null | Cherbourg | 0 |\n", + "| 7 | Abelson, Mrs. Samuel | female | 0.34864 | … | 24.00000 | null | Cherbourg | 1 |\n", + "| | (Hannah W… | | | | | | | |\n", + "| 8 | Abrahamsson, Mr. | male | 0.24843 | … | 7.92500 | null | Southampton | 1 |\n", + "| | Abraham Augus… | | | | | | | |\n", + "| 9 | Abrahim, Mrs. Joseph | female | 0.22338 | … | 7.22920 | null | Cherbourg | 1 |\n", + "| | (Sophie H… | | | | | | | |\n", + "+-----+-----------------------+--------+---------+---+----------+-------+---------------+----------+" + ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 11 + "source": [ + "from safeds.data.tabular.transformation import RangeScaler\n", + "\n", + "scaler = RangeScaler(column_names=\"age\", min_=0.0, max_=1.0).fit(titanic)\n", + "scaler.transform(titanic_slice)" + ] }, { "cell_type": "markdown", - "source": [ - "5. Transform table using `StandardScaler`, this will standardize values of chosen `Column`s:" - ], "metadata": { "collapsed": false - } + }, + "source": [ + "5. Transform table using `StandardScaler`, this will standardize values of chosen `Column`s:" + ] }, { "cell_type": "code", - "source": [ - "from safeds.data.tabular.transformation import StandardScaler\n", - "\n", - "scaler = StandardScaler(column_names=[\"age\", \"travel_class\"]).fit(titanic)\n", - "scaler.transform(titanic_slice)" - ], + "execution_count": 12, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.604030100Z", "start_time": "2024-05-24T11:02:33.486926500Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+\n| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n| --- | --- | --- | --- | | --- | --- | --- | --- |\n| i64 | str | str | f64 | | f64 | str | str | i64 |\n+==================================================================================================+\n| 0 | Abbing, Mr. Anthony | male | 0.84120 | … | 7.55000 | null | Southampton | 0 |\n| 1 | Abbott, Master. | male | -1.17176 | … | 20.25000 | null | Southampton | 0 |\n| | Eugene Joseph | | | | | | | |\n| 2 | Abbott, Mr. Rossmore | male | -0.96353 | … | 20.25000 | null | Southampton | 0 |\n| | Edward | | | | | | | |\n| 3 | Abbott, Mrs. Stanton | female | 0.35531 | … | 20.25000 | null | Southampton | 1 |\n| | (Rosa Hun… | | | | | | | |\n| 4 | Abelseth, Miss. | female | -0.96353 | … | 7.65000 | null | Southampton | 1 |\n| | Karen Marie | | | | | | | |\n| 5 | Abelseth, Mr. Olaus | male | -0.33881 | … | 7.65000 | F G63 | Southampton | 1 |\n| | Jorgensen | | | | | | | |\n| 6 | Abelson, Mr. Samuel | male | 0.00825 | … | 24.00000 | null | Cherbourg | 0 |\n| 7 | Abelson, Mrs. Samuel | female | -0.13057 | … | 24.00000 | null | Cherbourg | 1 |\n| | (Hannah W… | | | | | | | |\n| 8 | Abrahamsson, Mr. | male | -0.68588 | … | 7.92500 | null | Southampton | 1 |\n| | Abraham Augus… | | | | | | | |\n| 9 | Abrahim, Mrs. Joseph | female | -0.82470 | … | 7.22920 | null | Cherbourg | 1 |\n| | (Sophie H… | | | | | | | |\n+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+", - "text/html": "
\nshape: (10, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64strstrf64i64i64strf64f64strstri64
0"Abbing, Mr. Anthony""male"0.84120200"C.A. 5547"0.8419167.55null"Southampton"0
1"Abbott, Master. Eugene Joseph""male"-1.17176302"C.A. 2673"0.84191620.25null"Southampton"0
2"Abbott, Mr. Rossmore Edward""male"-0.96352611"C.A. 2673"0.84191620.25null"Southampton"0
3"Abbott, Mrs. Stanton (Rosa Hun…"female"0.35531411"C.A. 2673"0.84191620.25null"Southampton"1
4"Abelseth, Miss. Karen Marie""female"-0.96352600"348125"0.8419167.65null"Southampton"1
5"Abelseth, Mr. Olaus Jorgensen""male"-0.33881200"348122"0.8419167.65"F G63""Southampton"1
6"Abelson, Mr. Samuel""male"0.00825110"P/PP 3381"-0.35209124.0null"Cherbourg"0
7"Abelson, Mrs. Samuel (Hannah W…"female"-0.13057410"P/PP 3381"-0.35209124.0null"Cherbourg"1
8"Abrahamsson, Mr. Abraham Augus…"male"-0.68587500"SOTON/O2 3101284"0.8419167.925null"Southampton"1
9"Abrahim, Mrs. Joseph (Sophie H…"female"-0.824700"2657"0.8419167.2292null"Cherbourg"1
" + "text/html": [ + "
\n", + "shape: (10, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64strstrf64i64i64strf64f64strstri64
0"Abbing, Mr. Anthony""male"0.84120200"C.A. 5547"0.8419167.55null"Southampton"0
1"Abbott, Master. Eugene Joseph""male"-1.17176302"C.A. 2673"0.84191620.25null"Southampton"0
2"Abbott, Mr. Rossmore Edward""male"-0.96352611"C.A. 2673"0.84191620.25null"Southampton"0
3"Abbott, Mrs. Stanton (Rosa Hun…"female"0.35531411"C.A. 2673"0.84191620.25null"Southampton"1
4"Abelseth, Miss. Karen Marie""female"-0.96352600"348125"0.8419167.65null"Southampton"1
5"Abelseth, Mr. Olaus Jorgensen""male"-0.33881200"348122"0.8419167.65"F G63""Southampton"1
6"Abelson, Mr. Samuel""male"0.00825110"P/PP 3381"-0.35209124.0null"Cherbourg"0
7"Abelson, Mrs. Samuel (Hannah W…"female"-0.13057410"P/PP 3381"-0.35209124.0null"Cherbourg"1
8"Abrahamsson, Mr. Abraham Augus…"male"-0.68587500"SOTON/O2 3101284"0.8419167.925null"Southampton"1
9"Abrahim, Mrs. Joseph (Sophie H…"female"-0.824700"2657"0.8419167.2292null"Cherbourg"1
" + ], + "text/plain": [ + "+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+\n", + "| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n", + "| --- | --- | --- | --- | | --- | --- | --- | --- |\n", + "| i64 | str | str | f64 | | f64 | str | str | i64 |\n", + "+==================================================================================================+\n", + "| 0 | Abbing, Mr. Anthony | male | 0.84120 | … | 7.55000 | null | Southampton | 0 |\n", + "| 1 | Abbott, Master. | male | -1.17176 | … | 20.25000 | null | Southampton | 0 |\n", + "| | Eugene Joseph | | | | | | | |\n", + "| 2 | Abbott, Mr. Rossmore | male | -0.96353 | … | 20.25000 | null | Southampton | 0 |\n", + "| | Edward | | | | | | | |\n", + "| 3 | Abbott, Mrs. Stanton | female | 0.35531 | … | 20.25000 | null | Southampton | 1 |\n", + "| | (Rosa Hun… | | | | | | | |\n", + "| 4 | Abelseth, Miss. | female | -0.96353 | … | 7.65000 | null | Southampton | 1 |\n", + "| | Karen Marie | | | | | | | |\n", + "| 5 | Abelseth, Mr. Olaus | male | -0.33881 | … | 7.65000 | F G63 | Southampton | 1 |\n", + "| | Jorgensen | | | | | | | |\n", + "| 6 | Abelson, Mr. Samuel | male | 0.00825 | … | 24.00000 | null | Cherbourg | 0 |\n", + "| 7 | Abelson, Mrs. Samuel | female | -0.13057 | … | 24.00000 | null | Cherbourg | 1 |\n", + "| | (Hannah W… | | | | | | | |\n", + "| 8 | Abrahamsson, Mr. | male | -0.68588 | … | 7.92500 | null | Southampton | 1 |\n", + "| | Abraham Augus… | | | | | | | |\n", + "| 9 | Abrahim, Mrs. Joseph | female | -0.82470 | … | 7.22920 | null | Cherbourg | 1 |\n", + "| | (Sophie H… | | | | | | | |\n", + "+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+" + ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 12 + "source": [ + "from safeds.data.tabular.transformation import StandardScaler\n", + "\n", + "scaler = StandardScaler(column_names=[\"age\", \"travel_class\"]).fit(titanic)\n", + "scaler.transform(titanic_slice)" + ] }, { "cell_type": "markdown", + "metadata": { + "collapsed": false + }, "source": [ "## Transform column\n", "\n", "1. Transform values of \"parents_children\" `Column` into true or false, depending on whether passenger travelled with parents or children:" - ], - "metadata": { - "collapsed": false - } + ] }, { "cell_type": "code", - "source": [ - "titanic_slice.transform_column(\"parents_children\", lambda cell: cell > 0)" - ], + "execution_count": 13, "metadata": { - "collapsed": false, "ExecuteTime": { "end_time": "2024-05-24T11:02:33.615541800Z", "start_time": "2024-05-24T11:02:33.494976800Z" - } + }, + "collapsed": false }, "outputs": [ { "data": { - "text/plain": "+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+\n| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n| --- | --- | --- | --- | | --- | --- | --- | --- |\n| i64 | str | str | f64 | | f64 | str | str | i64 |\n+==================================================================================================+\n| 0 | Abbing, Mr. Anthony | male | 42.00000 | … | 7.55000 | null | Southampton | 0 |\n| 1 | Abbott, Master. | male | 13.00000 | … | 20.25000 | null | Southampton | 0 |\n| | Eugene Joseph | | | | | | | |\n| 2 | Abbott, Mr. Rossmore | male | 16.00000 | … | 20.25000 | null | Southampton | 0 |\n| | Edward | | | | | | | |\n| 3 | Abbott, Mrs. Stanton | female | 35.00000 | … | 20.25000 | null | Southampton | 1 |\n| | (Rosa Hun… | | | | | | | |\n| 4 | Abelseth, Miss. | female | 16.00000 | … | 7.65000 | null | Southampton | 1 |\n| | Karen Marie | | | | | | | |\n| 5 | Abelseth, Mr. Olaus | male | 25.00000 | … | 7.65000 | F G63 | Southampton | 1 |\n| | Jorgensen | | | | | | | |\n| 6 | Abelson, Mr. Samuel | male | 30.00000 | … | 24.00000 | null | Cherbourg | 0 |\n| 7 | Abelson, Mrs. Samuel | female | 28.00000 | … | 24.00000 | null | Cherbourg | 1 |\n| | (Hannah W… | | | | | | | |\n| 8 | Abrahamsson, Mr. | male | 20.00000 | … | 7.92500 | null | Southampton | 1 |\n| | Abraham Augus… | | | | | | | |\n| 9 | Abrahim, Mrs. Joseph | female | 18.00000 | … | 7.22920 | null | Cherbourg | 1 |\n| | (Sophie H… | | | | | | | |\n+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+", - "text/html": "
\nshape: (10, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64strstrf64i64boolstri64f64strstri64
0"Abbing, Mr. Anthony""male"42.00false"C.A. 5547"37.55null"Southampton"0
1"Abbott, Master. Eugene Joseph""male"13.00true"C.A. 2673"320.25null"Southampton"0
2"Abbott, Mr. Rossmore Edward""male"16.01true"C.A. 2673"320.25null"Southampton"0
3"Abbott, Mrs. Stanton (Rosa Hun…"female"35.01true"C.A. 2673"320.25null"Southampton"1
4"Abelseth, Miss. Karen Marie""female"16.00false"348125"37.65null"Southampton"1
5"Abelseth, Mr. Olaus Jorgensen""male"25.00false"348122"37.65"F G63""Southampton"1
6"Abelson, Mr. Samuel""male"30.01false"P/PP 3381"224.0null"Cherbourg"0
7"Abelson, Mrs. Samuel (Hannah W…"female"28.01false"P/PP 3381"224.0null"Cherbourg"1
8"Abrahamsson, Mr. Abraham Augus…"male"20.00false"SOTON/O2 3101284"37.925null"Southampton"1
9"Abrahim, Mrs. Joseph (Sophie H…"female"18.00false"2657"37.2292null"Cherbourg"1
" + "text/html": [ + "
\n", + "shape: (10, 12)
idnamesexagesiblings_spousesparents_childrentickettravel_classfarecabinport_embarkedsurvived
i64strstrf64i64boolstri64f64strstri64
0"Abbing, Mr. Anthony""male"42.00false"C.A. 5547"37.55null"Southampton"0
1"Abbott, Master. Eugene Joseph""male"13.00true"C.A. 2673"320.25null"Southampton"0
2"Abbott, Mr. Rossmore Edward""male"16.01true"C.A. 2673"320.25null"Southampton"0
3"Abbott, Mrs. Stanton (Rosa Hun…"female"35.01true"C.A. 2673"320.25null"Southampton"1
4"Abelseth, Miss. Karen Marie""female"16.00false"348125"37.65null"Southampton"1
5"Abelseth, Mr. Olaus Jorgensen""male"25.00false"348122"37.65"F G63""Southampton"1
6"Abelson, Mr. Samuel""male"30.01false"P/PP 3381"224.0null"Cherbourg"0
7"Abelson, Mrs. Samuel (Hannah W…"female"28.01false"P/PP 3381"224.0null"Cherbourg"1
8"Abrahamsson, Mr. Abraham Augus…"male"20.00false"SOTON/O2 3101284"37.925null"Southampton"1
9"Abrahim, Mrs. Joseph (Sophie H…"female"18.00false"2657"37.2292null"Cherbourg"1
" + ], + "text/plain": [ + "+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+\n", + "| id | name | sex | age | … | fare | cabin | port_embarked | survived |\n", + "| --- | --- | --- | --- | | --- | --- | --- | --- |\n", + "| i64 | str | str | f64 | | f64 | str | str | i64 |\n", + "+==================================================================================================+\n", + "| 0 | Abbing, Mr. Anthony | male | 42.00000 | … | 7.55000 | null | Southampton | 0 |\n", + "| 1 | Abbott, Master. | male | 13.00000 | … | 20.25000 | null | Southampton | 0 |\n", + "| | Eugene Joseph | | | | | | | |\n", + "| 2 | Abbott, Mr. Rossmore | male | 16.00000 | … | 20.25000 | null | Southampton | 0 |\n", + "| | Edward | | | | | | | |\n", + "| 3 | Abbott, Mrs. Stanton | female | 35.00000 | … | 20.25000 | null | Southampton | 1 |\n", + "| | (Rosa Hun… | | | | | | | |\n", + "| 4 | Abelseth, Miss. | female | 16.00000 | … | 7.65000 | null | Southampton | 1 |\n", + "| | Karen Marie | | | | | | | |\n", + "| 5 | Abelseth, Mr. Olaus | male | 25.00000 | … | 7.65000 | F G63 | Southampton | 1 |\n", + "| | Jorgensen | | | | | | | |\n", + "| 6 | Abelson, Mr. Samuel | male | 30.00000 | … | 24.00000 | null | Cherbourg | 0 |\n", + "| 7 | Abelson, Mrs. Samuel | female | 28.00000 | … | 24.00000 | null | Cherbourg | 1 |\n", + "| | (Hannah W… | | | | | | | |\n", + "| 8 | Abrahamsson, Mr. | male | 20.00000 | … | 7.92500 | null | Southampton | 1 |\n", + "| | Abraham Augus… | | | | | | | |\n", + "| 9 | Abrahim, Mrs. Joseph | female | 18.00000 | … | 7.22920 | null | Cherbourg | 1 |\n", + "| | (Sophie H… | | | | | | | |\n", + "+-----+----------------------+--------+----------+---+----------+-------+---------------+----------+" + ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], - "execution_count": 13 + "source": [ + "titanic_slice.transform_column(\"parents_children\", lambda cell: cell > 0)" + ] } ], "metadata": { diff --git a/src/safeds/data/tabular/transformation/_range_scaler.py b/src/safeds/data/tabular/transformation/_range_scaler.py index c54b60dc8..3a93be88b 100644 --- a/src/safeds/data/tabular/transformation/_range_scaler.py +++ b/src/safeds/data/tabular/transformation/_range_scaler.py @@ -37,13 +37,7 @@ class RangeScaler(InvertibleTableTransformer): # Dunder methods # ------------------------------------------------------------------------------------------------------------------ - def __init__( - self, - min_: float = 0.0, - max_: float = 1.0, - *, - column_names: str | list[str] | None = None, - ) -> None: + def __init__(self, *, column_names: str | list[str] | None = None, min_: float = 0.0, max_: float = 1.0) -> None: super().__init__(column_names) if min_ >= max_: