<jupyter_start><jupyter_text>Linear, Non-Linear ExamplesObjective: visualize linear, quadratic, cubic, exponential, log, sine functions on a plot<jupyter_code>%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import math
def log_func(x):
    if x > 0:
        return math.log(x,10)
    else:
        return np.nan
df = pd.DataFrame(index=range(-200,200))
df.shape
title = ['Linear 3*X','Quadratic X^2',
         'Cubic X^3','Absolute abs(X)',
         'sine(X)','log(X)',
         'Exponential 2^X']

df['linear']=df.index.map(lambda x: 3*x)
df['quadratic'] = df.index.map(lambda x: x**2)
df['cubic'] = df.index.map(lambda x: x**3)
df['abs'] = df.index.map(lambda x: abs(x))
df['sine'] = np.sin(np.arange(-20,20,.1))
df['log'] = df.index.map(log_func)
df['exponential'] = df.index.map(lambda x: 2.0**x)
df.head()
df.tail()
fig, axs = plt.subplots(2, 2, figsize=(10, 10), sharex=False)
axx = axs.ravel()
for i in range(df.shape[1]-3):
    axx[i].set_title(title[i])
    df[df.columns[i]].plot(ax=axx[i])
    axx[i].set_xlabel('X')
    if i % 2 == 1 :
        axx[i].yaxis.tick_right()
    axx[i].grid()
plt.figure(figsize=(10,3))
plt.plot(df['exponential'])
plt.title('Exponential 2^X')
plt.xlim(-10,20)
plt.ylim(0,100000)
plt.xlabel('X')
plt.grid()
plt.figure(figsize=(10,3))
plt.plot(df['log'])
plt.title('Log(X)')
plt.xlim(-10,200)
plt.xlabel('X')
plt.grid()
plt.figure(figsize=(10,3))
plt.plot(np.arange(-20,20,.1), df['sine'])
plt.title('Sine(X)')
plt.xlabel('X')
plt.grid()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.21705426356589147, 'fraction_numerical': 0.041343669250646, 'mean_word_length': 4.673992673992674, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '311695', 'license': 'Apache-2.0', 'n_tokens_mistral': 717, 'n_tokens_neox': 657, 'n_words': 119, 'path': '00 Introduction/ml_linear_non_linear.ipynb', 'repo_name': 'jaypeeml/AWSSagemaker', 'size': '1548'}