Best Python code snippet using pytest-django_python
split_data_8-1-1_sample_item.py
Source: split_data_8-1-1_sample_item.py
1#!/bin/python2import pandas as pd3import numpy as np4from time import gmtime, strftime567def now():8 return strftime("%Y-%m-%d %H:%M:%S", gmtime())910ratings_train = pd.DataFrame()11ratings_test = pd.DataFrame()12ratings_train_80 = pd.DataFrame()13ratings_test_10 = pd.DataFrame()14test_input = pd.DataFrame()15test_eval = pd.DataFrame()16test_input_10 = pd.DataFrame()17test_eval_10 = pd.DataFrame()1819print now(), 'start clean'20ratings = pd.read_csv('../cleaned_rating.dat', header=None, sep=' ', names=['u', 'i', 'r'])21users = (ratings['u'].unique())22print now(), 'splitting train-test'23for user in users:24 # 90-1025 items = ratings[ratings['u'] == user]['i'].unique()26 items = np.random.permutation(items)27 k = int(round(items.shape[0] * 0.9))28 train_items = items[:k]29 test_items = items[k:]30 ratings_train = ratings_train.append(ratings[(ratings['u'] == user) & (ratings['i'].isin(train_items))])31 test_transactions = ratings[(ratings['u'] == user) & (ratings['i'].isin(test_items))]32 ratings_test = ratings_test.append(test_transactions)33 # splitting test34 n = test_transactions.shape[0]35 k = int(round(n / 2.0))36 test_input = test_input.append(test_transactions.iloc[:k, :])37 test_eval = test_eval.append(test_transactions.iloc[k:, :])38 # 80-10 in 9039 k = int(round((8 / 9.0) * train_items.shape[0]))40 train_items_80 = train_items[:k]41 test_items_10 = train_items[k:]42 ratings_train_80 = ratings_train_80.append(ratings[(ratings['u'] == user) & (ratings['i'].isin(train_items_80))])43 test_transactions = ratings[(ratings['u'] == user) & (ratings['i'].isin(test_items_10))]44 ratings_test_10 = ratings_test_10.append(test_transactions)45 # splitting test46 n = test_transactions.shape[0]47 k = int(round(n / 2.0))48 test_input_10 = test_input_10.append(test_transactions.iloc[:k, :])49 test_eval_10 = test_eval_10.append(test_transactions.iloc[k:, :])5051ratings_train.to_csv('./ratings_train.dat', header=False, sep=' ', index=False)52ratings_train_iuv = ratings_train[['i', 'u', 'r']]53ratings_train_iuv.to_csv('./ratings_train_iuv.dat', header=False, sep=' ', index=False)5455ratings_train_80.to_csv('./ratings_train_80.dat', header=False, sep=' ', index=False)56ratings_train_80_iuv = ratings_train_80[['i', 'u', 'r']]57ratings_train_80_iuv.to_csv('./ratings_train_80_iuv.dat', header=False, sep=' ', index=False)5859test_input = test_input[['u', 'i', 'r']].astype(int)60test_eval = test_eval[['u', 'i', 'r']].astype(int)6162test_input_10 = test_input_10[['u', 'i', 'r']].astype(int)63test_eval_10 = test_eval_10[['u', 'i', 'r']].astype(int)6465test_input.to_csv('./ratings_test_input.dat', header=False, sep=' ', index=False)66test_eval.to_csv('./ratings_test_eval.dat', header=False, sep=' ', index=False)6768test_input_10.to_csv('./ratings_train_input.dat', header=False, sep=' ', index=False)69test_eval_10.to_csv('./ratings_train_eval.dat', header=False, sep=' ', index=False)7071pd.DataFrame(test_eval['u'].unique()).to_csv('./target_users.dat', header=False, sep=' ', index=False)72pd.DataFrame(test_eval_10['u'].unique()).to_csv('./train_target_users.dat', header=False, sep=' ', index=False)
...
split_data_6-2-2_sample_item.py
Source: split_data_6-2-2_sample_item.py
1#!/bin/python2import pandas as pd3import numpy as np4from time import gmtime, strftime567def now():8 return strftime("%Y-%m-%d %H:%M:%S", gmtime())910ratings_train = pd.DataFrame()11ratings_test = pd.DataFrame()12ratings_train_80 = pd.DataFrame()13ratings_test_10 = pd.DataFrame()14test_input = pd.DataFrame()15test_eval = pd.DataFrame()16test_input_10 = pd.DataFrame()17test_eval_10 = pd.DataFrame()1819print now(), 'start clean'20ratings = pd.read_csv('../cleaned_rating.dat', header=None, sep=' ', names=['u', 'i', 'r'])21users = (ratings['u'].unique())22print now(), 'splitting train-test'23for user in users:24 # 90-1025 items = ratings[ratings['u'] == user]['i'].unique()26 items = np.random.permutation(items)27 k = int(round(items.shape[0] * 0.8))28 train_items = items[:k]29 test_items = items[k:]30 ratings_train = ratings_train.append(ratings[(ratings['u'] == user) & (ratings['i'].isin(train_items))])31 test_transactions = ratings[(ratings['u'] == user) & (ratings['i'].isin(test_items))]32 ratings_test = ratings_test.append(test_transactions)33 # splitting test34 n = test_transactions.shape[0]35 k = int(round(n / 2.0))36 test_input = test_input.append(test_transactions.iloc[:k, :])37 test_eval = test_eval.append(test_transactions.iloc[k:, :])38 # 80-10 in 9039 k = int(round((6 / 8.0) * train_items.shape[0]))40 train_items_80 = train_items[:k]41 test_items_10 = train_items[k:]42 ratings_train_80 = ratings_train_80.append(ratings[(ratings['u'] == user) & (ratings['i'].isin(train_items_80))])43 test_transactions = ratings[(ratings['u'] == user) & (ratings['i'].isin(test_items_10))]44 ratings_test_10 = ratings_test_10.append(test_transactions)45 # splitting test46 n = test_transactions.shape[0]47 k = int(round(n / 2.0))48 test_input_10 = test_input_10.append(test_transactions.iloc[:k, :])49 test_eval_10 = test_eval_10.append(test_transactions.iloc[k:, :])5051ratings_train.to_csv('./ratings_train.dat', header=False, sep=' ', index=False)52ratings_train_iuv = ratings_train[['i', 'u', 'r']]53ratings_train_iuv.to_csv('./ratings_train_iuv.dat', header=False, sep=' ', index=False)5455ratings_train_80.to_csv('./ratings_train_80.dat', header=False, sep=' ', index=False)56ratings_train_80_iuv = ratings_train_80[['i', 'u', 'r']]57ratings_train_80_iuv.to_csv('./ratings_train_80_iuv.dat', header=False, sep=' ', index=False)5859test_input = test_input[['u', 'i', 'r']].astype(int)60test_eval = test_eval[['u', 'i', 'r']].astype(int)6162test_input_10 = test_input_10[['u', 'i', 'r']].astype(int)63test_eval_10 = test_eval_10[['u', 'i', 'r']].astype(int)6465test_input.to_csv('./ratings_test_input.dat', header=False, sep=' ', index=False)66test_eval.to_csv('./ratings_test_eval.dat', header=False, sep=' ', index=False)6768test_input_10.to_csv('./ratings_train_input.dat', header=False, sep=' ', index=False)69test_eval_10.to_csv('./ratings_train_eval.dat', header=False, sep=' ', index=False)7071pd.DataFrame(test_eval['u'].unique()).to_csv('./target_users.dat', header=False, sep=' ', index=False)72pd.DataFrame(test_eval_10['u'].unique()).to_csv('./train_target_users.dat', header=False, sep=' ', index=False)
...
pipelines_test.py
Source: pipelines_test.py
1"""Tests for the Machine Learning Helpers."""2# pylint: disable=missing-docstring3from beancount.parser import parser4from smart_importer.pipelines import AttrGetter5TEST_DATA, _, __ = parser.parse_string(6 """72016-01-01 open Assets:US:BofA:Checking USD82016-01-01 open Expenses:Food:Groceries USD92016-01-01 open Expenses:Food:Coffee USD102016-01-06 * "Farmer Fresh" "Buying groceries"11 Assets:US:BofA:Checking -10.00 USD122016-01-07 * "Starbucks" "Coffee"13 Assets:US:BofA:Checking -4.00 USD14 Expenses:Food:Coffee152016-01-07 * "Farmer Fresh" "Groceries"16 Assets:US:BofA:Checking -11.20 USD17 Expenses:Food:Groceries182016-01-08 * "Gimme Coffee" "Coffee"19 Assets:US:BofA:Checking -3.50 USD20 Expenses:Food:Coffee21"""22)23TEST_TRANSACTIONS = TEST_DATA[3:]24TEST_TRANSACTION = TEST_TRANSACTIONS[0]25def test_get_payee():26 assert AttrGetter("payee").transform(TEST_TRANSACTIONS) == [27 "Farmer Fresh",28 "Starbucks",29 "Farmer Fresh",30 "Gimme Coffee",31 ]32def test_get_narration():33 assert AttrGetter("narration").transform(TEST_TRANSACTIONS) == [34 "Buying groceries",35 "Coffee",36 "Groceries",37 "Coffee",38 ]39def test_get_metadata():40 txn = TEST_TRANSACTION41 txn.meta["attr"] = "value"42 assert AttrGetter("meta.attr").transform([txn]) == ["value"]43 assert AttrGetter("meta.attr", "default").transform(TEST_TRANSACTIONS) == [44 "value",45 "default",46 "default",47 "default",48 ]49def test_get_day_of_month():...
Check out the latest blogs from LambdaTest on this topic:
Hey Folks! Welcome back to the latest edition of LambdaTest’s product updates. Since programmer’s day is just around the corner, our incredible team of developers came up with several new features and enhancements to add some zing to your workflow. We at LambdaTest are continuously upgrading the features on our platform to make lives easy for the QA community. We are releasing new functionality almost every week.
Technical debt was originally defined as code restructuring, but in today’s fast-paced software delivery environment, it has evolved. Technical debt may be anything that the software development team puts off for later, such as ineffective code, unfixed defects, lacking unit tests, excessive manual tests, or missing automated tests. And, like financial debt, it is challenging to pay back.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
If you are a web tester then somewhere down the road you will have to come across Selenium, an open-source test automation framework that has been on boom ever since its launch in 2004.
The web paradigm has changed considerably over the last few years. Web 2.0, a term coined way back in 1999, was one of the pivotal moments in the history of the Internet. UGC (User Generated Content), ease of use, and interoperability for the end-users were the key pillars of Web 2.0. Consumers who were only consuming content up till now started creating different forms of content (e.g., text, audio, video, etc.).
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!