gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
titan dataset code
- User
titan dataset code
- Assistant
To work with the Titan dataset, you can use various programming languages such as Python or R. Here's an example code in Python using the Pandas library to load and analyze the dataset:
import pandas as pd # Load the dataset df = pd.read_csv('titan.csv') # Display the first few rows of the dataset print(df.head()) # Basic data exploration print(df.info()) # Display the information about the dataset print(df.describe()) # Display basic statistical measures of the dataset # Data analysis and visualization print(df['Age'].mean()) # Calculate the average age of passengers print(df['Survived'].value_counts()) # Count the number of survivors and non-survivors df['Sex'].value_counts().plot(kind='bar') # Visualize the count of passengers by gender # Data filtering and slicing female_passengers = df[df['Sex'] == 'female'] # Filter passengers by gender print(female_passengers.head()) age_greater_than_60 = df[df['Age'] > 60] # Filter passengers by age print(age_greater_than_60.head())Make sure to replace the
'titan.csv'with the actual path or URL of the Titan dataset file on your system. - User
titan data full code
- Assistant
Here's a full code example that includes loading the Titanic dataset, data preprocessing, exploratory data analysis, and machine learning modeling using the Scikit-learn library in Python:
import pandas as pd import matplotlib.pyplot as plt import seaborn as sns from sklearn.model_selection import train_test_split from sklearn.tree import DecisionTreeClassifier from sklearn.metrics import accuracy_score # Load the Titanic dataset df = pd.read_csv('titan.csv') # Data preprocessing df.drop(['PassengerId', 'Name', 'Ticket', 'Cabin', 'Embarked'], axis=1, inplace=True) df['Sex'] = df['Sex'].map({'female': 0, 'male': 1}) df['Age'].fillna(df['Age'].median(), inplace=True) # Exploratory Data Analysis sns.countplot(x='Survived', data=df) plt.show() sns.countplot(x='Survived', hue='Sex', data=df) plt.show() sns.countplot(x='Survived', hue='Pclass', data=df) plt.show() sns.displot(df['Age']) plt.show() # Split the dataset into features and target variable X = df.drop('Survived', axis=1) y = df['Survived'] # Split the dataset into training and testing sets X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42) # Train a Decision Tree classifier clf = DecisionTreeClassifier() clf.fit(X_train, y_train) # Predict the target variable for testing set y_pred = clf.predict(X_test) # Evaluate the model's accuracy accuracy = accuracy_score(y_test, y_pred) print("Accuracy:", accuracy)