recomend-intake optimize.py testing


In [1]:
import scipy
import scipy.stats
import matplotlib
import pylab
import seaborn
import pandas

%matplotlib inline

In [2]:
import optimize
from micro_reqs import ALL_MICROS

# RDA and UL vectors
columns, RDA, UL = [], [], []
for n, _, _, r, u in ALL_MICROS:
    columns.append(n) #string
    RDA.append(r)
    UL.append(u)

RDA, UL = scipy.array(RDA), scipy.array(UL)

# Food details and food as nutrient vectors
food_details = list(optimize.read_foods("foods.jsontxt.gz"))
foods = scipy.array([optimize.extract_nutrients(f) for f in food_details])

# Food normialized as percent of RDA
foods_rda = pandas.DataFrame(
    foods / RDA, # foods is F x N matrix, RDA is 1 x N vector, division operator does point-wise div per row
    columns=columns
)

In [3]:
print(foods_rda[:12][["Vitamin B6", "Vitamin B12", "Magnesium", "Calcium"]])
seaborn.regplot("Magnesium", "Calcium", foods_rda)


    Vitamin B6  Vitamin B12  Magnesium   Calcium
0     0.015882            0   0.011905  0.005833
1     0.055882            0   0.028571  0.005000
2     0.021176            0   0.309524  0.143333
3     0.150588            0   0.619048  0.037500
4     0.025882            0   0.007143  0.004167
5     0.031765            0   0.016667  0.006667
6     0.017647            0   0.047619  0.024167
7     0.025882            0   0.021429  0.013333
8     0.038235            0   0.014286  0.008333
9     0.021176            0   0.047619  0.051667
10    0.005294            0   0.009524  0.073333
11    0.043529            0   0.042857  0.012500
Out[3]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f5c3f03f748>

In [4]:
rnds = scipy.stats.binom.rvs(1420.0, 5/1420.0, size=10000)
rnds = pandas.DataFrame(rnds, columns=['R'])
seaborn.distplot(rnds)


Out[4]:
<matplotlib.axes._subplots.AxesSubplot at 0x7f5c3f017278>

In [5]:
for food in sorted(food_details, key=lambda f: f['descrip'].lower()):
    print(food['descrip'])


Alfalfa seeds, sprouted, raw
Apples, canned, sweetened, sliced, drained, heated
Apples, canned, sweetened, sliced, drained, unheated
Apples, dried, sulfured, stewed, without added sugar
Apples, dried, sulfured, uncooked
Apples, raw, with skin
Apples, raw, without skin
Apples, raw, without skin, cooked, boiled
Apples, raw, without skin, cooked, microwave
Apricots, canned, water pack, with skin, solids and liquids
Apricots, dried, sulfured, stewed, without added sugar
Apricots, dried, sulfured, uncooked
Apricots, raw
Artichokes, (globe or french), cooked, boiled, drained, without salt
Artichokes, (globe or french), frozen, cooked, boiled, drained, without salt
Arugula, raw
Asparagus, canned, drained solids
Asparagus, cooked, boiled, drained
Asparagus, frozen, cooked, boiled, drained, without salt
Asparagus, raw
Avocados, raw, all commercial varieties
Balsam-pear (bitter gourd), leafy tips, cooked, boiled, drained, without salt
Balsam-pear (bitter gourd), pods, cooked, boiled, drained, without salt
Bamboo shoots, canned, drained solids
Bamboo shoots, raw
Bananas, raw
Barley, pearled, cooked
Barley, pearled, raw
Beans, baked, canned, no salt added
Beans, black turtle, mature seeds, cooked, boiled, without salt
Beans, black, mature seeds, canned, low sodium
Beans, black, mature seeds, raw
Beans, great northern, mature seeds, canned, low sodium
Beans, kidney, all types, mature seeds, cooked, boiled, without salt
Beans, kidney, red, mature seeds, canned, solids and liquids
Beans, kidney, red, mature seeds, cooked, boiled, without salt
Beans, kidney, red, mature seeds, raw
Beans, mature, red kidney, canned, solids and liquid, low sodium
Beans, mung, mature seeds, sprouted, canned, drained solids
Beans, navy, mature seeds, canned
Beans, pink, mature seeds, cooked, boiled, without salt
Beans, pink, mature seeds, raw
Beans, pinto, mature seeds, canned, solids and liquids, low sodium
Beans, pinto, mature seeds, cooked, boiled, without salt
Beans, pinto, mature seeds, raw
Beans, shellie, canned, solids and liquids
Beans, snap, green, canned, no salt added, drained solids
Beans, snap, green, canned, regular pack, drained solids
Beans, snap, green, cooked, boiled, drained, without salt
Beans, snap, green, frozen, cooked, boiled, drained without salt
Beans, snap, green, raw
Beans, snap, yellow, canned, regular pack, drained solids
Beans, snap, yellow, cooked, boiled, drained, without salt
Beans, snap, yellow, frozen, cooked, boiled, drained, without salt
Beans, white, mature seeds, cooked, boiled, without salt
Beans, white, mature seeds, raw
Beet greens, cooked, boiled, drained, without salt
Beet greens, raw
Beets, canned, drained solids
Beets, canned, no salt added, solids and liquids
Beets, cooked, boiled, drained
Beets, pickled, canned, solids and liquids
Beets, raw
Blackberries, frozen, unsweetened
Blackberries, raw
Blueberries, dried, sweetened
Blueberries, frozen, sweetened
Blueberries, frozen, unsweetened
Blueberries, raw
Boysenberries, frozen, unsweetened
Breadfruit, raw
Broadbeans (fava beans), mature seeds, cooked, boiled, without salt
Broadbeans (fava beans), mature seeds, raw
Broccoli raab, cooked
Broccoli raab, raw
Broccoli, chinese, cooked
Broccoli, cooked, boiled, drained, without salt
Broccoli, frozen, chopped, cooked, boiled, drained, without salt
Broccoli, frozen, chopped, unprepared
Broccoli, frozen, spears, cooked, boiled, drained, without salt
Broccoli, raw
Brussels sprouts, cooked, boiled, drained, without salt
Brussels sprouts, frozen, cooked, boiled, drained, without salt
Brussels sprouts, raw
Burdock root, cooked, boiled, drained, without salt
Burdock root, raw
Cabbage, chinese (pak-choi), cooked, boiled, drained, without salt
Cabbage, chinese (pak-choi), raw
Cabbage, chinese (pe-tsai), raw
Cabbage, cooked, boiled, drained, without salt
Cabbage, japanese style, fresh, pickled
Cabbage, mustard, salted
Cabbage, raw
Cabbage, red, cooked, boiled, drained, without salt
Cabbage, red, raw
Cabbage, savoy, raw
Carambola, (starfruit), raw
Carrots, canned, no salt added, solids and liquids
Carrots, canned, regular pack, drained solids
Carrots, cooked, boiled, drained, without salt
Carrots, frozen, cooked, boiled, drained, without salt
Carrots, frozen, unprepared
Carrots, raw
Cassava, raw
Cauliflower, cooked, boiled, drained, without salt
Cauliflower, frozen, cooked, boiled, drained, without salt
Cauliflower, frozen, unprepared
Cauliflower, green, raw
Cauliflower, raw
Celeriac, raw
Celery, cooked, boiled, drained, without salt
Celery, raw
Cereals ready-to-eat, KASHI GO LEAN CRUNCH!, Honey Almond Flax
Cereals ready-to-eat, KASHI GOLEAN
Cereals ready-to-eat, KASHI GOLEAN CRUNCH!
Cereals ready-to-eat, KASHI GOOD FRIENDS
Cereals ready-to-eat, KASHI HEART TO HEART, Honey Toasted Oat
Cereals ready-to-eat, KASHI Honey Sunshine
Cereals ready-to-eat, KASHI, HEART TO HEART, Oat Flakes & Blueberry Clusters
Chard, swiss, cooked, boiled, drained, without salt
Chard, swiss, raw
Chayote, fruit, raw
Cherries, sour, red, canned, water pack, solids and liquids (includes USDA commodity red tart cherries, canned)
Cherries, sour, red, frozen, unsweetened
Cherries, sour, red, raw
Cherries, tart, dried, sweetened
Chickpeas (garbanzo beans, bengal gram), mature seeds, canned, solids and liquids, low sodium
Chickpeas (garbanzo beans, bengal gram), mature seeds, cooked, boiled, without salt
Chickpeas (garbanzo beans, bengal gram), mature seeds, raw
Chicory greens, raw
Chives, raw
Chrysanthemum, garland, cooked, boiled, drained, without salt
Collards, cooked, boiled, drained, without salt
Collards, frozen, chopped, cooked, boiled, drained, without salt
Collards, raw
Corn bran, crude
Cowpeas (blackeyes), immature seeds, cooked, boiled, drained, without salt
Cowpeas (blackeyes), immature seeds, frozen, cooked, boiled, drained, without salt
Cowpeas, common (blackeyes, crowder, southern), mature seeds, cooked, boiled, without salt
Cowpeas, common (blackeyes, crowder, southern), mature seeds, raw
Cranberries, dried, sweetened
Cranberries, raw
Cranberry sauce, canned, sweetened
Cress, garden, cooked, boiled, drained, without salt
Cress, garden, raw
Cucumber, peeled, raw
Cucumber, with peel, raw
Currants, red and white, raw
Currants, zante, dried
Dandelion greens, cooked, boiled, drained, without salt
Dandelion greens, raw
Dates, deglet noor
Drumstick leaves, cooked, boiled, drained, without salt
Eggplant, cooked, boiled, drained, without salt
Eggplant, pickled
Eggplant, raw
Endive, raw
Fennel, bulb, raw
Figs, canned, water pack, solids and liquids
Figs, dried, stewed
Figs, dried, uncooked
Figs, raw
Garlic, raw
Ginger root, raw
Grape leaves, raw
Grapefruit, raw, pink and red and white, all areas
Grapefruit, raw, white, all areas
Grapefruit, sections, canned, water pack, solids and liquids
Grapes, american type (slip skin), raw
Grapes, canned, thompson seedless, water pack, solids and liquids
Grapes, red or green (European type, such as Thompson seedless), raw
Guava sauce, cooked
Guavas, common, raw
Hearts of palm, raw
Jerusalem-artichokes, raw
Jute, potherb, cooked, boiled, drained, without salt
Kale, cooked, boiled, drained, without salt
Kale, frozen, cooked, boiled, drained, without salt
Kiwifruit, green, raw
Kohlrabi, cooked, boiled, drained, without salt
Kohlrabi, raw
Kumquats, raw
Leeks, (bulb and lower leaf-portion), raw
Lemon peel, raw
Lemons, raw, without peel
Lentils, mature seeds, cooked, boiled, without salt
Lentils, raw
Lettuce, butterhead (includes boston and bibb types), raw
Lettuce, cos or romaine, raw
Lettuce, green leaf, raw
Lettuce, iceberg (includes crisphead types), raw
Lima beans, immature seeds, canned, no salt added, solids and liquids
Lima beans, immature seeds, cooked, boiled, drained, without salt
Lima beans, immature seeds, frozen, baby, cooked, boiled, drained, without salt
Lima beans, immature seeds, frozen, fordhook, cooked, boiled, drained, without salt
Lima beans, immature seeds, frozen, fordhook, unprepared
Lima beans, immature seeds, raw
Lima beans, large, mature seeds, cooked, boiled, without salt
Lima beans, large, mature seeds, raw
Limes, raw
Litchis, dried
Litchis, raw
Loganberries, frozen
Lotus root, cooked, boiled, drained, without salt
Mangos, raw
Maraschino cherries, canned, drained
Melons, cantaloupe, raw
Melons, casaba, raw
Melons, honeydew, raw
Miso
Mulberries, raw
Mung beans, mature seeds, cooked, boiled, without salt
Mung beans, mature seeds, raw
Mung beans, mature seeds, sprouted, cooked, boiled, drained, with salt
Mung beans, mature seeds, sprouted, cooked, boiled, drained, without salt
Mung beans, mature seeds, sprouted, raw
Mungo beans, mature seeds, cooked, boiled, without salt
Mushrooms, canned, drained solids
Mushrooms, shiitake, cooked, without salt
Mushrooms, shiitake, dried
Mushrooms, white, cooked, boiled, drained, without salt
Mushrooms, white, raw
Mustard greens, cooked, boiled, drained, without salt
Mustard greens, frozen, cooked, boiled, drained, without salt
Mustard greens, raw
Natto
Nopales, cooked, without salt
Nopales, raw
Nuts, almond butter, plain, with salt added
Nuts, almond paste
Nuts, almonds
Nuts, almonds, blanched
Nuts, almonds, dry roasted, with salt added
Nuts, almonds, dry roasted, without salt added
Nuts, almonds, oil roasted, with salt added
Nuts, almonds, oil roasted, without salt added
Nuts, brazilnuts, dried, unblanched
Nuts, cashew butter, plain, with salt added
Nuts, cashew nuts, dry roasted, with salt added
Nuts, cashew nuts, dry roasted, without salt added
Nuts, cashew nuts, oil roasted, with salt added
Nuts, cashew nuts, oil roasted, without salt added
Nuts, chestnuts, european, roasted
Nuts, coconut cream, canned, sweetened
Nuts, coconut meat, dried (desiccated), not sweetened
Nuts, coconut meat, dried (desiccated), sweetened, flaked, packaged
Nuts, coconut meat, dried (desiccated), sweetened, shredded
Nuts, coconut meat, raw
Nuts, coconut milk, raw (liquid expressed from grated meat and water)
Nuts, hazelnuts or filberts
Nuts, macadamia nuts, dry roasted, with salt added
Nuts, mixed nuts, dry roasted, with peanuts, with salt added
Nuts, mixed nuts, oil roasted, with peanuts, with salt added
Nuts, mixed nuts, oil roasted, without peanuts, with salt added
Nuts, pecans
Nuts, pine nuts, dried
Nuts, pistachio nuts, dry roasted, with salt added
Nuts, pistachio nuts, dry roasted, without salt added
Nuts, walnuts, black, dried
Nuts, walnuts, english
Oat bran, raw
Okra, cooked, boiled, drained, without salt
Okra, frozen, cooked, boiled, drained, without salt
Okra, frozen, unprepared
Okra, raw
Olives, pickled, canned or bottled, green
Olives, ripe, canned (jumbo-super colossal)
Olives, ripe, canned (small-extra large)
Onions, cooked, boiled, drained, with salt
Onions, cooked, boiled, drained, without salt
Onions, frozen, chopped, cooked, boiled, drained, without salt
Onions, frozen, whole, cooked, boiled, drained, without salt
Onions, frozen, whole, unprepared
Onions, raw
Onions, spring or scallions (includes tops and bulb), raw
Onions, young green, tops only
Oranges, raw, all commercial varieties
Papad
Papayas, raw
Parsley, fresh
Parsnips, cooked, boiled, drained, without salt
Passion-fruit, (granadilla), purple, raw
Peaches, canned, water pack, solids and liquids
Peaches, dried, sulfured, stewed, without added sugar
Peaches, dried, sulfured, uncooked
Peaches, frozen, sliced, sweetened
Peaches, raw
Peanut butter, chunk style, without salt
Peanut butter, chunky, vitamin and mineral fortified
Peanut butter, reduced sodium
Peanut butter, smooth style, with salt
Peanut butter, smooth style, without salt
Peanut butter, smooth, reduced fat
Peanut butter, smooth, vitamin and mineral fortified
Peanuts, all types, cooked, boiled, with salt
Peanuts, all types, dry-roasted, with salt
Peanuts, all types, dry-roasted, without salt
Peanuts, all types, raw
Pears, asian, raw
Pears, canned, water pack, solids and liquids
Pears, dried, sulfured, stewed, without added sugar
Pears, dried, sulfured, uncooked
Pears, raw
Peas and carrots, canned, no salt added, solids and liquids
Peas and carrots, frozen, cooked, boiled, drained, without salt
Peas and onions, frozen, cooked, boiled, drained, without salt
Peas, edible-podded, boiled, drained, without salt
Peas, edible-podded, frozen, cooked, boiled, drained, without salt
Peas, edible-podded, raw
Peas, green (includes baby and lesuer types), canned, drained solids, unprepared
Peas, green, canned, no salt added, solids and liquids
Peas, green, cooked, boiled, drained, without salt
Peas, green, frozen, cooked, boiled, drained, without salt
Peas, green, frozen, unprepared
Peas, green, raw
Peas, green, split, mature seeds, raw
Peas, split, mature seeds, cooked, boiled, without salt
Pepper, banana, raw
Peppers, hot chile, sun-dried
Peppers, jalapeno, raw
Peppers, serrano, raw
Persimmons, japanese, raw
Pickles, cucumber, dill or kosher dill
Pickles, cucumber, sour
Pickles, cucumber, sour, low sodium
Pickles, cucumber, sweet (includes bread and butter pickles)
Pigeonpeas, immature seeds, cooked, boiled, drained, without salt
Pigeonpeas, immature seeds, raw
Pimento, canned
Pineapple, canned, water pack, solids and liquids
Pineapple, frozen, chunks, sweetened
Pineapple, raw, all varieties
Plantains, cooked
Plantains, raw
Plums, canned, purple, water pack, solids and liquids
Plums, dried (prunes), stewed, without added sugar
Plums, dried (prunes), uncooked
Plums, raw
Poi
Pokeberry shoots, (poke), cooked, boiled, drained, without salt
Pomegranates, raw
Potatoes, baked, flesh and skin, without salt
Potatoes, baked, flesh, without salt
Potatoes, baked, skin, without salt
Potatoes, boiled, cooked in skin, flesh, with salt
Potatoes, boiled, cooked in skin, flesh, without salt
Potatoes, boiled, cooked without skin, flesh, with salt
Potatoes, boiled, cooked without skin, flesh, without salt
Potatoes, canned, drained solids, no salt added
Potatoes, flesh and skin, raw
Potatoes, frozen, whole, unprepared
Pumpkin flowers, cooked, boiled, drained, without salt
Pumpkin leaves, cooked, boiled, drained, without salt
Pumpkin, canned, without salt
Pumpkin, cooked, boiled, drained, without salt
Pumpkin, raw
Quinoa, cooked
Radicchio, raw
Radishes, hawaiian style, pickled
Radishes, oriental, cooked, boiled, drained, without salt
Radishes, oriental, raw
Radishes, raw
Raisins, golden seedless
Raisins, seedless
Raspberries, frozen, red, sweetened
Raspberries, raw
Rhubarb, frozen, cooked, with sugar
Rhubarb, frozen, uncooked
Rhubarb, raw
Rutabagas, cooked, boiled, drained, without salt
Rutabagas, raw
Rye grain
Salsify, cooked, boiled, drained, without salt
Sauerkraut, canned, low sodium
Sauerkraut, canned, solids and liquids
Seaweed, agar, dried
Seaweed, agar, raw
Seaweed, irishmoss, raw
Seaweed, kelp, raw
Seaweed, laver, raw
Seaweed, spirulina, dried
Seaweed, wakame, raw
Seeds, flaxseed
Seeds, pumpkin and squash seed kernels, dried
Seeds, pumpkin and squash seed kernels, roasted, with salt added
Seeds, pumpkin and squash seed kernels, roasted, without salt
Seeds, sesame butter, tahini, from roasted and toasted kernels (most common type)
Seeds, sesame seed kernels, dried (decorticated)
Seeds, sesame seed kernels, toasted, with salt added (decorticated)
Seeds, sesame seed kernels, toasted, without salt added (decorticated)
Seeds, sesame seeds, whole, dried
Seeds, sunflower seed kernels, dried
Seeds, sunflower seed kernels, dry roasted, with salt added
Seeds, sunflower seed kernels, dry roasted, without salt
Seeds, sunflower seed kernels, oil roasted, with salt added
Seeds, sunflower seed kernels, oil roasted, without salt
Soursop, raw
Soy protein isolate
Soy sauce made from hydrolyzed vegetable protein
Soy sauce made from soy (tamari)
Soybean, curd cheese
Soybeans, mature cooked, boiled, without salt
Soybeans, mature seeds, roasted, salted
Soybeans, mature seeds, sprouted, cooked, steamed
Spinach, canned, regular pack, drained solids
Spinach, cooked, boiled, drained, without salt
Spinach, frozen, chopped or leaf, cooked, boiled, drained, without salt
Spinach, frozen, chopped or leaf, unprepared
Spinach, raw
Squash, summer, all varieties, cooked, boiled, drained, without salt
Squash, summer, all varieties, raw
Squash, summer, crookneck and straightneck, canned, drained, solid, without salt
Squash, summer, crookneck and straightneck, cooked, boiled, drained, without salt
Squash, summer, crookneck and straightneck, frozen, cooked, boiled, drained, without salt
Squash, summer, scallop, cooked, boiled, drained, without salt
Squash, summer, zucchini, includes skin, cooked, boiled, drained, without salt
Squash, summer, zucchini, includes skin, frozen, cooked, boiled, drained, without salt
Squash, summer, zucchini, includes skin, raw
Squash, winter, all varieties, cooked, baked, without salt
Squash, winter, all varieties, raw
Strawberries, frozen, sweetened, sliced
Strawberries, frozen, sweetened, whole
Strawberries, frozen, unsweetened
Strawberries, raw
Sweet potato leaves, cooked, steamed, without salt
Sweet potato, canned, vacuum pack
Sweet potato, cooked, baked in skin, flesh, without salt
Sweet potato, cooked, boiled, without skin
Sweet potato, raw, unprepared
Tamarinds, raw
Tangerines, (mandarin oranges), raw
Tofu yogurt
Tofu, soft, prepared with calcium sulfate and magnesium chloride (nigari)
Tomatillos, raw
Tomatoes, green, raw
Tomatoes, red, ripe, canned, stewed
Tomatoes, red, ripe, cooked
Tomatoes, red, ripe, raw, year round average
Tomatoes, sun-dried
Turnip greens and turnips, frozen, cooked, boiled, drained, without salt
Turnip greens, canned, no salt added
Turnip greens, cooked, boiled, drained, without salt
Turnip greens, frozen, cooked, boiled, drained, without salt
Turnips, cooked, boiled, drained, without salt
Turnips, frozen, cooked, boiled, drained, without salt
Turnips, raw
Waterchestnuts, chinese, (matai), raw
Waterchestnuts, chinese, canned, solids and liquids
Watercress, raw
Watermelon, raw
Waxgourd, (chinese preserving melon), cooked, boiled, drained, without salt
Yam, cooked, boiled, drained, or baked, with salt
Yam, cooked, boiled, drained, or baked, without salt
Yam, raw
Yambean (jicama), raw