Skip to content

Instantly share code, notes, and snippets.

@andresbravog
Created November 22, 2018 08:35
Show Gist options
  • Save andresbravog/4d4c7f15a1cccc45d7ecffd3f6cba64e to your computer and use it in GitHub Desktop.
Save andresbravog/4d4c7f15a1cccc45d7ecffd3f6cba64e to your computer and use it in GitHub Desktop.
Actividad 2.3
import pandas as pd
import numpy as np
from tensorflow.python.lib.io import file_io
import json
import csv
total_examples = 100
filename = './andres_bravo_dataset.csv'
# x4 mean and standard distribution values
mu, sigma = 0, 1
# Generates Dataset for Activity 2.3 with:
# * 1 feature strong dependant
# * 3 features weekly dependant
# * 1 feature independant (gausian distribution)
def generate_dataset():
global total_examples, filename
total_examples_generated = 0
f = csv.writer(open(filename, "wb+"))
# Write CSV Header, If you dont need that, remove this line
f.writerow(["x0", "x1", "x2", "x3", "x4", "class"])
for x0 in [0, 1]:
for x1 in [0, 1]:
for x2 in [0, 1]:
for x3 in [0, 1]:
for x4 in np.random.normal(mu, sigma, 10):
if total_examples_generated == total_examples:
return
f.writerow([x0,x1,x2,x3,x4,class_function(x0, x1, x2, x3, x4)])
total_examples_generated = total_examples_generated + 1
# Defines the class funcition for the dataset
def class_function(x0, x1, x2, x3, x4):
return x0 or (x1 and x2 and x3)
generate_dataset()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment