# history

source:
  import matplotlib.pyplot as plt
  import numpy as np

  # Generate 1000 random data points from a normal (Gaussian) distribution
  data = np.random.randn(1000)

  # Create the histogram
  plt.hist(data, bins=30, color='skyblue', edgecolor='black')

  # Add labels and title
  plt.title("Histogram of Random Data")
  plt.xlabel("Value")
  plt.ylabel("Frequency")

  # Show the plot
  plt.show()

source_raw:
  import matplotlib.pyplot as plt
  import numpy as np

  # Generate 1000 random data points from a normal (Gaussian) distribution
  data = np.random.randn(1000)

  # Create the histogram
  plt.hist(data, bins=30, color='skyblue', edgecolor='black')

  # Add labels and title
  plt.title("Histogram of Random Data")
  plt.xlabel("Value")
  plt.ylabel("Frequency")

  # Show the plot
  plt.show()


source:
  # -*- coding: utf-8 -*-

  # -----------------------------------------------
  # 5 Important Data Visualizations in Data Science
  # -----------------------------------------------
  get_ipython().system('pip install pandas')
  get_ipython().system('pip install matplotlib')
  get_ipython().system('pip install seaborn')
  get_ipython().system('pip install numpy')

source_raw:
  # -*- coding: utf-8 -*-

  # -----------------------------------------------
  # 5 Important Data Visualizations in Data Science
  # -----------------------------------------------
  !pip install pandas
  !pip install matplotlib
  !pip install seaborn
  !pip install numpy


source:
  # -----------------------------------------------
  # 5 Important Data Visualizations in Data Science
  # -----------------------------------------------

  import numpy as np
  import pandas as pd
  import matplotlib.pyplot as plt
  import seaborn as sns

  # Make plots look clean
  sns.set(style="whitegrid", palette="deep", font_scale=1.1)

  # Create sample data
  np.random.seed(42)
  data = pd.DataFrame({
      'Age': np.random.normal(35, 10, 200),
      'Income': np.random.normal(70000, 15000, 200),
      'Department': np.random.choice(['HR', 'Engineering', 'Marketing', 'Sales'], 200),
      'Experience': np.random.randint(1, 30, 200),
      'Month': pd.date_range('2024-01-01', periods=200, freq='M')
  })
  data['Sales'] = (data['Experience'] * 1000 + np.random.normal(0, 3000, 200)).astype(int)

source_raw:
  # -----------------------------------------------
  # 5 Important Data Visualizations in Data Science
  # -----------------------------------------------

  import numpy as np
  import pandas as pd
  import matplotlib.pyplot as plt
  import seaborn as sns

  # Make plots look clean
  sns.set(style="whitegrid", palette="deep", font_scale=1.1)

  # Create sample data
  np.random.seed(42)
  data = pd.DataFrame({
      'Age': np.random.normal(35, 10, 200),
      'Income': np.random.normal(70000, 15000, 200),
      'Department': np.random.choice(['HR', 'Engineering', 'Marketing', 'Sales'], 200),
      'Experience': np.random.randint(1, 30, 200),
      'Month': pd.date_range('2024-01-01', periods=200, freq='M')
  })
  data['Sales'] = (data['Experience'] * 1000 + np.random.normal(0, 3000, 200)).astype(int)


source:
  # -----------------------------------------------
  # 5 Important Data Visualizations in Data Science
  # -----------------------------------------------

  import numpy as np
  import pandas as pd
  import matplotlib.pyplot as plt
  import seaborn as sns

  # Make plots look clean
  sns.set(style="whitegrid", palette="deep", font_scale=1.1)

  # Create sample data
  np.random.seed(42)
  data = pd.DataFrame({
      'Age': np.random.normal(35, 10, 200),
      'Income': np.random.normal(70000, 15000, 200),
      'Department': np.random.choice(['HR', 'Engineering', 'Marketing', 'Sales'], 200),
      'Experience': np.random.randint(1, 30, 200),
      'Month': pd.date_range('2024-01-01', periods=200, freq='MS')
  })
  data['Sales'] = (data['Experience'] * 1000 + np.random.normal(0, 3000, 200)).astype(int)

source_raw:
  # -----------------------------------------------
  # 5 Important Data Visualizations in Data Science
  # -----------------------------------------------

  import numpy as np
  import pandas as pd
  import matplotlib.pyplot as plt
  import seaborn as sns

  # Make plots look clean
  sns.set(style="whitegrid", palette="deep", font_scale=1.1)

  # Create sample data
  np.random.seed(42)
  data = pd.DataFrame({
      'Age': np.random.normal(35, 10, 200),
      'Income': np.random.normal(70000, 15000, 200),
      'Department': np.random.choice(['HR', 'Engineering', 'Marketing', 'Sales'], 200),
      'Experience': np.random.randint(1, 30, 200),
      'Month': pd.date_range('2024-01-01', periods=200, freq='MS')
  })
  data['Sales'] = (data['Experience'] * 1000 + np.random.normal(0, 3000, 200)).astype(int)


source:
  # 1️⃣ Distribution – Histogram
  plt.figure(figsize=(7,5))
  sns.histplot(data['Age'], bins=20, kde=True, color='royalblue')
  plt.title("Distribution of Age")
  plt.xlabel("Age")
  plt.ylabel("Frequency")
  plt.show()

source_raw:
  # 1️⃣ Distribution – Histogram
  plt.figure(figsize=(7,5))
  sns.histplot(data['Age'], bins=20, kde=True, color='royalblue')
  plt.title("Distribution of Age")
  plt.xlabel("Age")
  plt.ylabel("Frequency")
  plt.show()


source:
  # 2️⃣ Comparison – Boxplot
  plt.figure(figsize=(7,5))
  sns.boxplot(x='Department', y='Income', data=data)
  plt.title("Income Comparison Across Departments")
  plt.xlabel("Department")
  plt.ylabel("Income ($)")
  plt.show()

source_raw:
  # 2️⃣ Comparison – Boxplot
  plt.figure(figsize=(7,5))
  sns.boxplot(x='Department', y='Income', data=data)
  plt.title("Income Comparison Across Departments")
  plt.xlabel("Department")
  plt.ylabel("Income ($)")
  plt.show()


source:
  # 3️⃣ Correlation – Scatterplot
  plt.figure(figsize=(7,5))
  sns.scatterplot(x='Age', y='Income', hue='Department', data=data, s=80)
  plt.title("Correlation between Age and Income")
  plt.xlabel("Age")
  plt.ylabel("Income ($)")
  plt.show()

source_raw:
  # 3️⃣ Correlation – Scatterplot
  plt.figure(figsize=(7,5))
  sns.scatterplot(x='Age', y='Income', hue='Department', data=data, s=80)
  plt.title("Correlation between Age and Income")
  plt.xlabel("Age")
  plt.ylabel("Income ($)")
  plt.show()


source:
  # 4️⃣ Composition – Pie Chart
  dept_counts = data['Department'].value_counts()
  plt.figure(figsize=(6,6))
  plt.pie(dept_counts, labels=dept_counts.index, autopct='%1.1f%%', startangle=90)
  plt.title("Department Composition")
  plt.show()

source_raw:
  # 4️⃣ Composition – Pie Chart
  dept_counts = data['Department'].value_counts()
  plt.figure(figsize=(6,6))
  plt.pie(dept_counts, labels=dept_counts.index, autopct='%1.1f%%', startangle=90)
  plt.title("Department Composition")
  plt.show()


source:
  # 5️⃣ Trend – Line Chart
  trend_data = data.groupby('Month')['Sales'].mean().reset_index()
  plt.figure(figsize=(8,5))
  plt.plot(trend_data['Month'], trend_data['Sales'], marker='o', color='green')
  plt.title("Average Sales Trend Over Time")
  plt.xlabel("Month")
  plt.ylabel("Average Sales ($)")
  plt.xticks(rotation=45)
  plt.tight_layout()
  plt.show()

source_raw:
  # 5️⃣ Trend – Line Chart
  trend_data = data.groupby('Month')['Sales'].mean().reset_index()
  plt.figure(figsize=(8,5))
  plt.plot(trend_data['Month'], trend_data['Sales'], marker='o', color='green')
  plt.title("Average Sales Trend Over Time")
  plt.xlabel("Month")
  plt.ylabel("Average Sales ($)")
  plt.xticks(rotation=45)
  plt.tight_layout()
  plt.show()


source:
  trend_data = data.groupby('Month')['Sales'].mean().reset_index()

  plt.figure(figsize=(8,5))

  # Line
  plt.plot(trend_data['Month'], trend_data['Sales'], color='green', linewidth=2)

  # Dots
  plt.scatter(trend_data['Month'], trend_data['Sales'],
              color='orange', edgecolor='black', s=60, zorder=3)

  plt.title("Average Sales Trend Over Time")
  plt.xlabel("Month")
  plt.ylabel("Average Sales ($)")
  plt.xticks(rotation=45)
  plt.tight_layout()
  plt.show()

source_raw:
  trend_data = data.groupby('Month')['Sales'].mean().reset_index()

  plt.figure(figsize=(8,5))

  # Line
  plt.plot(trend_data['Month'], trend_data['Sales'], color='green', linewidth=2)

  # Dots
  plt.scatter(trend_data['Month'], trend_data['Sales'],
              color='orange', edgecolor='black', s=60, zorder=3)

  plt.title("Average Sales Trend Over Time")
  plt.xlabel("Month")
  plt.ylabel("Average Sales ($)")
  plt.xticks(rotation=45)
  plt.tight_layout()
  plt.show()


source:
  trend_data = data.groupby('Month')['Sales'].mean().reset_index()

  plt.figure(figsize=(8,5))

  # Line
  plt.plot(trend_data['Month'], trend_data['Sales'], color='green', linewidth=2)

  # Dots
  plt.scatter(trend_data['Month'], trend_data['Sales'],
              color='yellow', edgecolor='black', s=60, zorder=3)

  plt.title("Average Sales Trend Over Time")
  plt.xlabel("Month")
  plt.ylabel("Average Sales ($)")
  plt.xticks(rotation=45)
  plt.tight_layout()
  plt.show()

source_raw:
  trend_data = data.groupby('Month')['Sales'].mean().reset_index()

  plt.figure(figsize=(8,5))

  # Line
  plt.plot(trend_data['Month'], trend_data['Sales'], color='green', linewidth=2)

  # Dots
  plt.scatter(trend_data['Month'], trend_data['Sales'],
              color='yellow', edgecolor='black', s=60, zorder=3)

  plt.title("Average Sales Trend Over Time")
  plt.xlabel("Month")
  plt.ylabel("Average Sales ($)")
  plt.xticks(rotation=45)
  plt.tight_layout()
  plt.show()


source:
  # Install required packages (uncomment when running in Colab or if packages are missing)
  # !pip install -q transformers torch seaborn matplotlib
  print("If running locally, ensure `transformers`, `torch`, `seaborn`, and `matplotlib` are installed.")

source_raw:
  # Install required packages (uncomment when running in Colab or if packages are missing)
  # !pip install -q transformers torch seaborn matplotlib
  print("If running locally, ensure `transformers`, `torch`, `seaborn`, and `matplotlib` are installed.")


source:
  from tensorflow.keras.models import Sequential
  from tensorflow.keras.layers import Embedding, SimpleRNN, LSTM, GRU, Dense
  from tensorflow.keras.preprocessing.text import Tokenizer
  from tensorflow.keras.preprocessing.sequence import pad_sequences
  import numpy as np

  texts = [
      "I love this movie", "This film was great", "Amazing performance",
      "I hate this movie", "This film was terrible", "Awful experience"
  ]
  labels = np.array([1, 1, 1, 0, 0, 0])

  tokenizer = Tokenizer(num_words=1000, oov_token="<OOV>")
  tokenizer.fit_on_texts(texts)
  X = pad_sequences(tokenizer.texts_to_sequences(texts), maxlen=5)

  def build_and_train(model_type):
      model = Sequential([
          Embedding(1000, 16, input_length=5),
          model_type(16),
          Dense(1, activation='sigmoid')
      ])
      model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
      print(f"Training {model_type.__name__}...")
      model.fit(X, labels, epochs=10, verbose=0)
      return model

  rnn_model = build_and_train(SimpleRNN)
  lstm_model = build_and_train(LSTM)
  gru_model = build_and_train(GRU)

  print('\nModel parameter summaries:')
  rnn_model.summary(); print('\n'); lstm_model.summary(); print('\n'); gru_model.summary()

source_raw:
  from tensorflow.keras.models import Sequential
  from tensorflow.keras.layers import Embedding, SimpleRNN, LSTM, GRU, Dense
  from tensorflow.keras.preprocessing.text import Tokenizer
  from tensorflow.keras.preprocessing.sequence import pad_sequences
  import numpy as np

  texts = [
      "I love this movie", "This film was great", "Amazing performance",
      "I hate this movie", "This film was terrible", "Awful experience"
  ]
  labels = np.array([1, 1, 1, 0, 0, 0])

  tokenizer = Tokenizer(num_words=1000, oov_token="<OOV>")
  tokenizer.fit_on_texts(texts)
  X = pad_sequences(tokenizer.texts_to_sequences(texts), maxlen=5)

  def build_and_train(model_type):
      model = Sequential([
          Embedding(1000, 16, input_length=5),
          model_type(16),
          Dense(1, activation='sigmoid')
      ])
      model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
      print(f"Training {model_type.__name__}...")
      model.fit(X, labels, epochs=10, verbose=0)
      return model

  rnn_model = build_and_train(SimpleRNN)
  lstm_model = build_and_train(LSTM)
  gru_model = build_and_train(GRU)

  print('\nModel parameter summaries:')
  rnn_model.summary(); print('\n'); lstm_model.summary(); print('\n'); gru_model.summary()


source:
  from transformers import pipeline
  clf = pipeline("sentiment-analysis")
  print(clf(["I love this movie", "This film was terrible"]))

source_raw:
  from transformers import pipeline
  clf = pipeline("sentiment-analysis")
  print(clf(["I love this movie", "This film was terrible"]))


source:
  import tensorflow


  from tensorflow.keras.models import Sequential
  from tensorflow.keras.layers import Embedding, SimpleRNN, LSTM, GRU, Dense
  from tensorflow.keras.preprocessing.text import Tokenizer
  from tensorflow.keras.preprocessing.sequence import pad_sequences
  import numpy as np

  texts = [
      "I love this movie", "This film was great", "Amazing performance",
      "I hate this movie", "This film was terrible", "Awful experience"
  ]
  labels = np.array([1, 1, 1, 0, 0, 0])

  tokenizer = Tokenizer(num_words=1000, oov_token="<OOV>")
  tokenizer.fit_on_texts(texts)
  X = pad_sequences(tokenizer.texts_to_sequences(texts), maxlen=5)

  def build_and_train(model_type):
      model = Sequential([
          Embedding(1000, 16, input_length=5),
          model_type(16),
          Dense(1, activation='sigmoid')
      ])
      model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
      print(f"Training {model_type.__name__}...")
      model.fit(X, labels, epochs=10, verbose=0)
      return model

  rnn_model = build_and_train(SimpleRNN)
  lstm_model = build_and_train(LSTM)
  gru_model = build_and_train(GRU)

  print('\nModel parameter summaries:')
  rnn_model.summary(); print('\n'); lstm_model.summary(); print('\n'); gru_model.summary()

source_raw:
  import tensorflow


  from tensorflow.keras.models import Sequential
  from tensorflow.keras.layers import Embedding, SimpleRNN, LSTM, GRU, Dense
  from tensorflow.keras.preprocessing.text import Tokenizer
  from tensorflow.keras.preprocessing.sequence import pad_sequences
  import numpy as np

  texts = [
      "I love this movie", "This film was great", "Amazing performance",
      "I hate this movie", "This film was terrible", "Awful experience"
  ]
  labels = np.array([1, 1, 1, 0, 0, 0])

  tokenizer = Tokenizer(num_words=1000, oov_token="<OOV>")
  tokenizer.fit_on_texts(texts)
  X = pad_sequences(tokenizer.texts_to_sequences(texts), maxlen=5)

  def build_and_train(model_type):
      model = Sequential([
          Embedding(1000, 16, input_length=5),
          model_type(16),
          Dense(1, activation='sigmoid')
      ])
      model.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])
      print(f"Training {model_type.__name__}...")
      model.fit(X, labels, epochs=10, verbose=0)
      return model

  rnn_model = build_and_train(SimpleRNN)
  lstm_model = build_and_train(LSTM)
  gru_model = build_and_train(GRU)

  print('\nModel parameter summaries:')
  rnn_model.summary(); print('\n'); lstm_model.summary(); print('\n'); gru_model.summary()


