# -*- coding: utf-8 -*-
"""Model_create_for_app.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1s8ModB_V8758ZvyZgJ4f_unrPCAXf0No
"""

import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.neighbors import NearestNeighbors
import spacy
from spacy.tokenizer import Tokenizer
from spacy.lang.en import English

df = pd.read_csv('https://raw.githubusercontent.com/calebmckay1/Unit-1-Build/master/toking.csv')


nlp=English()
tokenizer = Tokenizer(nlp.vocab)
tf = TfidfVectorizer(stop_words='english')


dtm = tf.fit_transform(df['search'])
dtm = pd.DataFrame(dtm.todense(), columns=tf.get_feature_names())


nn = NearestNeighbors(n_neighbors=5, algorithm='ball_tree')
nn.fit(dtm)


input = ['helps with insomnia']
dtf = tf.transform(input)
_, output = nn.kneighbors(dtf.todense())


recommendations = []
for n in output:
    for row in n:
        recommendations.append(row)


for i in recommendations:
    print(f"{df.loc[i,:]}\n")

def search_func(input):

  input = [input]
  nlp=English()
  tokenizer = Tokenizer(nlp.vocab)
  tf = TfidfVectorizer(stop_words='english')
  dtm = tf.fit_transform(df['search'])
  dtm = pd.DataFrame(dtm.todense(), columns=tf.get_feature_names())

  nn = NearestNeighbors(n_neighbors=5, algorithm='ball_tree')
  nn.fit(dtm)
  dtf = tf.transform(input)
  _, output = nn.kneighbors(dtf.todense())






  
  dtf = tf.transform(input)
  _, output = nn.kneighbors(dtf.todense())


  recommendations = []
  for n in output:
    for row in n:
        recommendations.append(row)

  result=[]
  for i in recommendations:
    data=(df.loc[i,:])
    result.append(data)
  return result

search_func(input = 'helps with insomnia')

f"{df.loc[i,:]}"
262aec64ab57448e5070cefb54f394860b657821
<mask token>


def search_func(input):
    input = [input]
    nlp = English()
    tokenizer = Tokenizer(nlp.vocab)
    tf = TfidfVectorizer(stop_words='english')
    dtm = tf.fit_transform(df['search'])
    dtm = pd.DataFrame(dtm.todense(), columns=tf.get_feature_names())
    nn = NearestNeighbors(n_neighbors=5, algorithm='ball_tree')
    nn.fit(dtm)
    dtf = tf.transform(input)
    _, output = nn.kneighbors(dtf.todense())
    dtf = tf.transform(input)
    _, output = nn.kneighbors(dtf.todense())
    recommendations = []
    for n in output:
        for row in n:
            recommendations.append(row)
    result = []
    for i in recommendations:
        data = df.loc[i, :]
        result.append(data)
    return result


<mask token>

<mask token>
nn.fit(dtm)
<mask token>
for n in output:
    for row in n:
        recommendations.append(row)
for i in recommendations:
    print(f'{df.loc[i, :]}\n')


def search_func(input):
    input = [input]
    nlp = English()
    tokenizer = Tokenizer(nlp.vocab)
    tf = TfidfVectorizer(stop_words='english')
    dtm = tf.fit_transform(df['search'])
    dtm = pd.DataFrame(dtm.todense(), columns=tf.get_feature_names())
    nn = NearestNeighbors(n_neighbors=5, algorithm='ball_tree')
    nn.fit(dtm)
    dtf = tf.transform(input)
    _, output = nn.kneighbors(dtf.todense())
    dtf = tf.transform(input)
    _, output = nn.kneighbors(dtf.todense())
    recommendations = []
    for n in output:
        for row in n:
            recommendations.append(row)
    result = []
    for i in recommendations:
        data = df.loc[i, :]
        result.append(data)
    return result


search_func(input='helps with insomnia')
f"""{df.loc[i, :]}"""

<mask token>
df = pd.read_csv(
    'https://raw.githubusercontent.com/calebmckay1/Unit-1-Build/master/toking.csv'
    )
nlp = English()
tokenizer = Tokenizer(nlp.vocab)
tf = TfidfVectorizer(stop_words='english')
dtm = tf.fit_transform(df['search'])
dtm = pd.DataFrame(dtm.todense(), columns=tf.get_feature_names())
nn = NearestNeighbors(n_neighbors=5, algorithm='ball_tree')
nn.fit(dtm)
input = ['helps with insomnia']
dtf = tf.transform(input)
_, output = nn.kneighbors(dtf.todense())
recommendations = []
for n in output:
    for row in n:
        recommendations.append(row)
for i in recommendations:
    print(f'{df.loc[i, :]}\n')


def search_func(input):
    input = [input]
    nlp = English()
    tokenizer = Tokenizer(nlp.vocab)
    tf = TfidfVectorizer(stop_words='english')
    dtm = tf.fit_transform(df['search'])
    dtm = pd.DataFrame(dtm.todense(), columns=tf.get_feature_names())
    nn = NearestNeighbors(n_neighbors=5, algorithm='ball_tree')
    nn.fit(dtm)
    dtf = tf.transform(input)
    _, output = nn.kneighbors(dtf.todense())
    dtf = tf.transform(input)
    _, output = nn.kneighbors(dtf.todense())
    recommendations = []
    for n in output:
        for row in n:
            recommendations.append(row)
    result = []
    for i in recommendations:
        data = df.loc[i, :]
        result.append(data)
    return result


search_func(input='helps with insomnia')
f"""{df.loc[i, :]}"""

<mask token>
import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.neighbors import NearestNeighbors
import spacy
from spacy.tokenizer import Tokenizer
from spacy.lang.en import English
df = pd.read_csv(
    'https://raw.githubusercontent.com/calebmckay1/Unit-1-Build/master/toking.csv'
    )
nlp = English()
tokenizer = Tokenizer(nlp.vocab)
tf = TfidfVectorizer(stop_words='english')
dtm = tf.fit_transform(df['search'])
dtm = pd.DataFrame(dtm.todense(), columns=tf.get_feature_names())
nn = NearestNeighbors(n_neighbors=5, algorithm='ball_tree')
nn.fit(dtm)
input = ['helps with insomnia']
dtf = tf.transform(input)
_, output = nn.kneighbors(dtf.todense())
recommendations = []
for n in output:
    for row in n:
        recommendations.append(row)
for i in recommendations:
    print(f'{df.loc[i, :]}\n')


def search_func(input):
    input = [input]
    nlp = English()
    tokenizer = Tokenizer(nlp.vocab)
    tf = TfidfVectorizer(stop_words='english')
    dtm = tf.fit_transform(df['search'])
    dtm = pd.DataFrame(dtm.todense(), columns=tf.get_feature_names())
    nn = NearestNeighbors(n_neighbors=5, algorithm='ball_tree')
    nn.fit(dtm)
    dtf = tf.transform(input)
    _, output = nn.kneighbors(dtf.todense())
    dtf = tf.transform(input)
    _, output = nn.kneighbors(dtf.todense())
    recommendations = []
    for n in output:
        for row in n:
            recommendations.append(row)
    result = []
    for i in recommendations:
        data = df.loc[i, :]
        result.append(data)
    return result


search_func(input='helps with insomnia')
f"""{df.loc[i, :]}"""

# -*- coding: utf-8 -*-
"""Model_create_for_app.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1s8ModB_V8758ZvyZgJ4f_unrPCAXf0No
"""

import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.neighbors import NearestNeighbors
import spacy
from spacy.tokenizer import Tokenizer
from spacy.lang.en import English

df = pd.read_csv('https://raw.githubusercontent.com/calebmckay1/Unit-1-Build/master/toking.csv')


nlp=English()
tokenizer = Tokenizer(nlp.vocab)
tf = TfidfVectorizer(stop_words='english')


dtm = tf.fit_transform(df['search'])
dtm = pd.DataFrame(dtm.todense(), columns=tf.get_feature_names())


nn = NearestNeighbors(n_neighbors=5, algorithm='ball_tree')
nn.fit(dtm)


input = ['helps with insomnia']
dtf = tf.transform(input)
_, output = nn.kneighbors(dtf.todense())


recommendations = []
for n in output:
    for row in n:
        recommendations.append(row)


for i in recommendations:
    print(f"{df.loc[i,:]}\n")

def search_func(input):

  input = [input]
  nlp=English()
  tokenizer = Tokenizer(nlp.vocab)
  tf = TfidfVectorizer(stop_words='english')
  dtm = tf.fit_transform(df['search'])
  dtm = pd.DataFrame(dtm.todense(), columns=tf.get_feature_names())

  nn = NearestNeighbors(n_neighbors=5, algorithm='ball_tree')
  nn.fit(dtm)
  dtf = tf.transform(input)
  _, output = nn.kneighbors(dtf.todense())






  
  dtf = tf.transform(input)
  _, output = nn.kneighbors(dtf.todense())


  recommendations = []
  for n in output:
    for row in n:
        recommendations.append(row)

  result=[]
  for i in recommendations:
    data=(df.loc[i,:])
    result.append(data)
  return result

search_func(input = 'helps with insomnia')

f"{df.loc[i,:]}"